-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelay.go
55 lines (43 loc) · 1.01 KB
/
relay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package crabfs
import (
"context"
"github.com/runletapp/crabfs/identity"
"github.com/runletapp/crabfs/interfaces"
"github.com/runletapp/crabfs/options"
)
// Relay controls a relay server
type Relay struct {
ctx context.Context
port uint
host interfaces.Core
}
// RelayNew creates a new relay instance
func RelayNew(ctx context.Context, port uint, bootstrapPeers []string, id identity.Identity) (*Relay, error) {
host, err := New(
options.Port(port),
options.RelayOnly(true),
options.BootstrapPeers(bootstrapPeers),
options.Identity(id),
)
if err != nil {
return nil, err
}
relay := &Relay{
ctx: ctx,
port: port,
host: host,
}
return relay, nil
}
// Close closes this relay instance
func (relay *Relay) Close() error {
return relay.host.Close()
}
// GetAddrs get the addresses that this node is bound to
func (relay *Relay) GetAddrs() []string {
return relay.host.GetAddrs()
}
// GetHostID returns the id of this p2p relay
func (relay *Relay) GetHostID() string {
return relay.host.GetID()
}