Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

docs and nits #66

Merged
merged 2 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ inet.Notifiee = (*RelayNotifiee)(nil)

type RelayNotifiee Relay

func (r *Relay) Notifiee() inet.Notifiee {
func (r *Relay) notifiee() inet.Notifiee {
return (*RelayNotifiee)(r)
}

Expand Down
19 changes: 16 additions & 3 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const maxMessageSize = 4096
var RelayAcceptTimeout = time.Minute
var HopConnectTimeout = 10 * time.Second

// Relay is the relay transport and service.
type Relay struct {
host host.Host
upgrader *tptu.Upgrader
Expand All @@ -47,11 +48,22 @@ type Relay struct {
lhLk sync.Mutex
}

// RelayOpts are options for configuring the relay transport.
type RelayOpt int

var (
OptActive = RelayOpt(0)
OptHop = RelayOpt(1)
// OptActive configures the relay transport to actively establish
// outbound connections on behalf of clients. You probably don't want to
// enable this unless you know what you're doing.
OptActive = RelayOpt(0)
// OptHop configures the relay transport to accept requests to relay
// traffic on behalf of third-parties. Unless OptActive is specified,
// this will only relay traffic between peers already connected to this
// node.
OptHop = RelayOpt(1)
// OptDiscovery configures this relay transport to discover new relays
// by probing every new peer. You almost _certainly_ don't want to
// enable this.
OptDiscovery = RelayOpt(2)
)

Expand All @@ -63,6 +75,7 @@ func (e RelayError) Error() string {
return fmt.Sprintf("error opening relay circuit: %s (%d)", pb.CircuitRelay_Status_name[int32(e.Code)], e.Code)
}

// NewRelay constructs a new relay.
func NewRelay(ctx context.Context, h host.Host, upgrader *tptu.Upgrader, opts ...RelayOpt) (*Relay, error) {
r := &Relay{
upgrader: upgrader,
Expand Down Expand Up @@ -90,7 +103,7 @@ func NewRelay(ctx context.Context, h host.Host, upgrader *tptu.Upgrader, opts ..
h.SetStreamHandler(ProtoID, r.handleNewStream)

if r.discovery {
h.Network().Notify(r.Notifiee())
h.Network().Notify(r.notifiee())
}

return r, nil
Expand Down