p2p/net: cleaned up dial events
+ fixed race
Juan Batiz-Benet committed
Jan 28, 2015 at 01:22 UTC
eb797706838ff71e2d5171f918bccab07ac6c8eb
3 files changed
+11
-11
p2p/net/conn/dial.go
-1
@@ -60,7 +60,6 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) (
60
61
c2, err := newSecureConn(ctx, d.PrivateKey, c)
62
if err != nil {
63
- logdial["error"] = err
63
errOut = err
64
c.Close()
65
return
p2p/net/swarm/swarm_dial.go
+11
-9
@@ -266,17 +266,18 @@ func (s *Swarm) gatedDialAttempt(ctx context.Context, p peer.ID) (*Conn, error)
266
// dial is the actual swarm's dial logic, gated by Dial.
267
func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
268
var logdial = lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil)
269
- defer log.EventBegin(ctx, "swarmDialDo", logdial).Done()
269
if p == s.local {
270
log.Event(ctx, "swarmDialDoDialSelf", logdial)
271
return nil, ErrDialToSelf
272
}
273
+ defer log.EventBegin(ctx, "swarmDialDo", logdial).Done()
274
+ logdial["dial"] = "failure" // start off with failure. set to "success" at the end.
275
276
sk := s.peers.PrivKey(s.local)
277
+ logdial["encrypted"] = (sk != nil) // log wether this will be an encrypted dial or not.
278
if sk == nil {
277
- // may be fine for sk to be nil, just log.
279
+ // fine for sk to be nil, just log.
280
log.Debug("Dial not given PrivateKey, so WILL NOT SECURE conn.")
279
- log.Event(ctx, "swarmDialDoInsecure", logdial)
281
}
282
283
// get our own addrs. try dialing out from our listener addresses (reusing ports)
@@ -298,7 +299,9 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
299
remoteAddrs = addrutil.Subtract(remoteAddrs, s.peers.Addresses(s.local))
300
log.Debugf("%s swarm dialing %s -- remote:%s local:%s", s.local, p, remoteAddrs, s.ListenAddresses())
301
if len(remoteAddrs) == 0 {
301
- return nil, errors.New("peer has no addresses")
302
+ err := errors.New("peer has no addresses")
303
+ logdial["error"] = err
304
+ return nil, err
305
}
306
307
// open connection to peer
@@ -316,20 +319,21 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
319
// try to get a connection to any addr
320
connC, err := s.dialAddrs(ctx, d, p, remoteAddrs)
321
if err != nil {
322
+ logdial["error"] = err
323
return nil, err
324
}
325
+ logdial["netconn"] = lgbl.NetConn(connC)
326
327
// ok try to setup the new connection.
328
defer log.EventBegin(ctx, "swarmDialDoSetup", logdial, lgbl.NetConn(connC)).Done()
329
swarmC, err := dialConnSetup(ctx, s, connC)
330
if err != nil {
326
- log.Debug("Dial newConnSetup failed. disconnecting.")
327
- log.Event(ctx, "swarmDialDoSetupFailed", logdial, lgbl.NetConn(connC), lgbl.Error(err))
331
+ logdial["error"] = err
332
connC.Close() // close the connection. didn't work out :(
333
return nil, err
334
}
335
332
- log.Event(ctx, "swarmDialDoSuccess", logdial, lgbl.NetConn(connC))
336
+ logdial["dial"] = "success"
337
return swarmC, nil
338
}
339
@@ -428,8 +432,6 @@ func dialConnSetup(ctx context.Context, s *Swarm, connC conn.Conn) (*Conn, error
432
// ok try to setup the new connection. (newConnSetup will add to group)
433
swarmC, err := s.newConnSetup(ctx, psC)
434
if err != nil {
431
- log.Debug("Dial newConnSetup failed. disconnecting.")
432
- log.Event(ctx, "dialFailureDisconnect", lgbl.NetConn(connC), lgbl.Error(err))
435
psC.Close() // we need to make sure psC is Closed.
436
return nil, err
437
}
util/eventlog/loggables/loggables.go
-1
@@ -37,7 +37,6 @@ func Dial(sys string, lid, rid peer.ID, laddr, raddr ma.Multiaddr) DeferredMap {
37
m["subsystem"] = sys
38
if lid != "" {
39
m["localPeer"] = func() interface{} { return lid.Pretty() }
40
- _ = m["localPeer"].(func() interface{})
40
}
41
if laddr != nil {
42
m["localAddr"] = func() interface{} { return laddr.String() }