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

expose CanHop as a module function #79

Merged
merged 1 commit into from
Aug 2, 2019
Merged
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
9 changes: 7 additions & 2 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ func (r *Relay) Matches(addr ma.Multiaddr) bool {
return err == nil
}

func (r *Relay) CanHop(ctx context.Context, id peer.ID) (bool, error) {
s, err := r.host.NewStream(ctx, id, ProtoID)
// Queries a peer for support of hop relay
func CanHop(ctx context.Context, host host.Host, id peer.ID) (bool, error) {
s, err := host.NewStream(ctx, id, ProtoID)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -233,6 +234,10 @@ func (r *Relay) CanHop(ctx context.Context, id peer.ID) (bool, error) {
return msg.GetCode() == pb.CircuitRelay_SUCCESS, nil
}

func (r *Relay) CanHop(ctx context.Context, id peer.ID) (bool, error) {
return CanHop(ctx, r.host, id)
}

func (r *Relay) handleNewStream(s network.Stream) {
log.Infof("new relay stream from: %s", s.Conn().RemotePeer())

Expand Down