Skip to content

Commit

Permalink
transport: rename DialUpdateKind enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Sep 15, 2023
1 parent 62b878b commit 807fe8f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
19 changes: 10 additions & 9 deletions core/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,22 @@ type DialUpdater interface {
type DialUpdateKind int

const (
// DialFailed indicates dial failed.
DialFailed DialUpdateKind = iota
// DialSuccessful indicates dial succeeded.
DialSuccessful
// TCPConnectionEstablished indicates successful completion of the TCP 3-way handshake
TCPConnectionEstablished
// UpdateKindDialFailed indicates dial failed.
UpdateKindDialFailed DialUpdateKind = iota
// UpdateKindDialSuccessful indicates dial succeeded.
UpdateKindDialSuccessful
// UpdateKindTCPConnectionEstablished indicates successful completion of the TCP 3-way
// handshake
UpdateKindTCPConnectionEstablished
)

func (k DialUpdateKind) String() string {
switch k {
case DialFailed:
case UpdateKindDialFailed:
return "DialFailed"
case DialSuccessful:
case UpdateKindDialSuccessful:
return "DialSuccessful"
case TCPConnectionEstablished:
case UpdateKindTCPConnectionEstablished:
return "TCPConnectionEstablished"
default:
return fmt.Sprintf("DialUpdateKind<Unknown-%d>", k)
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/dial_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ loop:

// TCP Connection has been established. Wait for connection upgrade on this address
// before making new dials.
if res.Kind == tpt.TCPConnectionEstablished {
if res.Kind == tpt.UpdateKindTCPConnectionEstablished {
// Only wait for public addresses to complete dialing since private dials
// are quick any way
if manet.IsPublicAddr(res.Addr) {
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/dial_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ func TestDialWorkerLoopTCPConnUpgradeWait(t *testing.T) {
// Wait a bit to let the loop make the dial attempt to a1
time.Sleep(1 * time.Second)
// Send conn established for a1
worker.resch <- transport.DialUpdate{Kind: transport.TCPConnectionEstablished, Addr: a1}
worker.resch <- transport.DialUpdate{Kind: transport.UpdateKindTCPConnectionEstablished, Addr: a1}
// Dial to a2 shouldn't happen even if a2 is scheduled to dial by now
cl.AdvanceBy(290 * time.Millisecond)
select {
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func (dl *dialLimiter) executeDial(j *dialJob) {
defer cancel()

con, err := dl.dialFunc(dctx, j.peer, j.addr, j.resp)
kind := transport.DialSuccessful
kind := transport.UpdateKindDialSuccessful
if err != nil {
kind = transport.DialFailed
kind = transport.UpdateKindDialFailed
}
select {
case j.resp <- transport.DialUpdate{Kind: kind, Conn: con, Addr: j.addr, Err: err}:
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (t *TcpTransport) dialWithScope(ctx context.Context, raddr ma.Multiaddr, p
}
if updCh != nil {
select {
case updCh <- transport.DialUpdate{Kind: transport.TCPConnectionEstablished, Addr: raddr}:
case updCh <- transport.DialUpdate{Kind: transport.UpdateKindTCPConnectionEstablished, Addr: raddr}:
default:
// It is better to skip the update than to delay upgrading the connection
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/transport/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestDialWithUpdates(t *testing.T) {
updCh := make(chan transport.DialUpdate, 1)
conn, err := tb.DialWithUpdates(context.Background(), ln.Multiaddr(), peerA, updCh)
upd := <-updCh
require.Equal(t, upd.Kind, transport.TCPConnectionEstablished)
require.Equal(t, upd.Kind, transport.UpdateKindTCPConnectionEstablished)
require.NotNil(t, conn)
require.NoError(t, err)

Expand All @@ -191,7 +191,7 @@ func TestDialWithUpdates(t *testing.T) {
// This dial will fail as acceptAndClose will not upgrade the connection
conn, err = tb.DialWithUpdates(context.Background(), li.Multiaddr(), peerA, updCh)
upd = <-updCh
require.Equal(t, upd.Kind, transport.TCPConnectionEstablished)
require.Equal(t, upd.Kind, transport.UpdateKindTCPConnectionEstablished)
require.Nil(t, conn)
require.Error(t, err)
}
Expand Down

0 comments on commit 807fe8f

Please sign in to comment.