},
Proxy: cl.config.HTTPProxy,
WebsocketTrackerHttpHeader: cl.config.WebsocketTrackerHttpHeader,
+ ICEServers: cl.config.ICEServers,
DialContext: cl.config.TrackerDialContext,
OnConn: func(dc datachannel.ReadWriteCloser, dcc webtorrent.DataChannelContext) {
cl.lock()
for {
conn, err := l.Accept()
torrent.Add("client listener accepts", 1)
+ if err == nil {
+ holepunchAddr, holepunchErr := addrPortFromPeerRemoteAddr(conn.RemoteAddr())
+ if holepunchErr == nil {
+ cl.lock()
+ if g.MapContains(cl.undialableWithoutHolepunch, holepunchAddr) {
+ setAdd(&cl.accepted, holepunchAddr)
+ }
+ if g.MapContains(
+ cl.undialableWithoutHolepunchDialedAfterHolepunchConnect,
+ holepunchAddr,
+ ) {
+ setAdd(&cl.probablyOnlyConnectedDueToHolepunch, holepunchAddr)
+ }
+ cl.unlock()
+ }
+ }
conn = pproffd.WrapNetConn(conn)
cl.rLock()
closed := cl.closed.IsSet()
log.Fmsg("error accepting connection: %s", err).LogLevel(log.Debug, cl.logger)
continue
}
- {
- holepunchAddr, holepunchErr := addrPortFromPeerRemoteAddr(conn.RemoteAddr())
- if holepunchErr == nil {
- cl.lock()
- if g.MapContains(
- cl.undialableWithoutHolepunchDialedAfterHolepunchConnect,
- holepunchAddr,
- ) {
- g.MakeMapIfNil(&cl.probablyOnlyConnectedDueToHolepunch)
- g.MapInsert(cl.probablyOnlyConnectedDueToHolepunch, holepunchAddr, struct{}{})
- }
- cl.unlock()
- }
- }
go func() {
if reject != nil {
torrent.Add("rejected accepted connections", 1)
}
}
holepunchAddr, holepunchAddrErr := addrPortFromPeerRemoteAddr(addr)
- if holepunchAddrErr == nil && opts.receivedHolepunchConnect {
- cl.lock()
- if g.MapContains(cl.undialableWithoutHolepunch, holepunchAddr) {
- g.MakeMapIfNilAndSet(
- &cl.undialableWithoutHolepunchDialedAfterHolepunchConnect,
- holepunchAddr,
- struct{}{},
- )
- }
- cl.unlock()
- }
headerObfuscationPolicy := opts.HeaderObfuscationPolicy
obfuscatedHeaderFirst := headerObfuscationPolicy.Preferred
firstDialResult := dialPool.getFirst()
torrent.Add("initiated conn with preferred header obfuscation", 1)
return
}
+ c.logger.Levelf(
+ log.Debug,
+ "error doing protocol handshake with header obfuscation %v",
+ obfuscatedHeaderFirst,
+ )
+ firstDialResult.Conn.Close()
// We should have just tried with the preferred header obfuscation. If it was required, there's nothing else to try.
if headerObfuscationPolicy.RequirePreferred {
return
torrent.Add("initiated conn with fallback header obfuscation", 1)
return
}
+ c.logger.Levelf(
+ log.Debug,
+ "error doing protocol handshake with header obfuscation %v",
+ !obfuscatedHeaderFirst,
+ )
+ secondDialResult.Conn.Close()
return
}
t.smartBanCache.Hash = sha1.Sum
t.smartBanCache.Init()
t.networkingEnabled.Set()
- t.logger = cl.logger.WithContextValue(t).WithNames("torrent", t.infoHash.HexString()).WithDefaultLevel(log.Debug)
+ t.logger = cl.logger.WithDefaultLevel(log.Debug)
t.sourcesLogger = t.logger.WithNames("sources")
if opts.ChunkSize == 0 {
opts.ChunkSize = defaultChunkSize
}
c.logger.Levelf(
log.Debug,
- "new PeerConn %p [Client %p remoteAddr %v network %v outgoing %t]",
- c, cl, opts.remoteAddr, opts.network, opts.outgoing,
+ "inited with remoteAddr %v network %v outgoing %t",
+ opts.remoteAddr, opts.network, opts.outgoing,
)
for _, f := range cl.config.Callbacks.NewPeer {
f(&c.Peer)