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

Commit

Permalink
Merge pull request #73 from libp2p/feat/stop-deadline
Browse files Browse the repository at this point in the history
set deadline for stop handshake
  • Loading branch information
vyzo authored May 2, 2019
2 parents d07cd5f + ba48830 commit b91a589
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ const ProtoID = "/libp2p/circuit/relay/0.1.0"

const maxMessageSize = 4096

var RelayAcceptTimeout = time.Minute
var HopConnectTimeout = 10 * time.Second
var (
RelayAcceptTimeout = 10 * time.Second
HopConnectTimeout = 30 * time.Second
StopHandshakeTimeout = 1 * time.Minute
)

// Relay is the relay transport and service.
type Relay struct {
Expand Down Expand Up @@ -328,6 +331,9 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
wr := newDelimitedWriter(bs)
defer rd.Close()

// set handshake deadline
bs.SetDeadline(time.Now().Add(StopHandshakeTimeout))

msg.Type = pb.CircuitRelay_STOP.Enum()

err = wr.WriteMsg(msg)
Expand Down Expand Up @@ -373,6 +379,9 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
// relay connection
log.Infof("relaying connection between %s and %s", src.ID.Pretty(), dst.ID.Pretty())

// reset deadline
bs.SetDeadline(time.Time{})

r.addLiveHop(src.ID, dst.ID)

// Don't reset streams after finishing or the other side will get an
Expand Down

0 comments on commit b91a589

Please sign in to comment.