From b906ca563bd0044c7e14b25c8292d7e40046a779 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 2 Aug 2019 11:34:23 +0300 Subject: [PATCH] expose CanHop as a module function --- p2p/protocol/internal/circuitv1-deprecated/relay.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/p2p/protocol/internal/circuitv1-deprecated/relay.go b/p2p/protocol/internal/circuitv1-deprecated/relay.go index 1bb7cc0d79..fcb1b5e262 100644 --- a/p2p/protocol/internal/circuitv1-deprecated/relay.go +++ b/p2p/protocol/internal/circuitv1-deprecated/relay.go @@ -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 } @@ -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())