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

set deadline for stop handshake #73

Merged
merged 3 commits into from
May 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
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