use the assigned role when upgrading a sim open connection

This commit is contained in:
Marten Seemann 2021-09-19 09:13:47 +01:00
parent 35074eed5b
commit e9c99b7e62
1 changed files with 8 additions and 2 deletions

View File

@ -8,12 +8,14 @@ import (
"runtime"
"time"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/transport"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
rtpt "github.com/libp2p/go-reuseport-transport"
logging "github.com/ipfs/go-log/v2"
ma "github.com/multiformats/go-multiaddr"
mafmt "github.com/multiformats/go-multiaddr-fmt"
manet "github.com/multiformats/go-multiaddr/net"
@ -148,7 +150,11 @@ func (t *TcpTransport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID)
if err != nil {
return nil, err
}
return t.Upgrader.UpgradeOutbound(ctx, t, c, p)
direction := network.DirOutbound
if ok, isClient, _ := network.GetSimultaneousConnect(ctx); ok && !isClient {
direction = network.DirInbound
}
return t.Upgrader.Upgrade(ctx, t, c, direction, p)
}
// UseReuseport returns true if reuseport is enabled and available.