func (t *transport) getConnection(addr Addr) (conn *connection, created bool) { var ( k = addr.Key() ) t.mtx.RLock() if t.conns != nil { conn = t.conns[k] } t.mtx.RUnlock() if conn == nil { t.mtx.Lock() if t.conns == nil { t.conns = make(map[interface{}]*connection) } conn = t.conns[k] if conn == nil { created = true conn = &connection{transport: t, raddr: addr} conn.halfPipe = transportsutil.NewHalfPipe() t.conns[k] = conn } t.mtx.Unlock() } return conn, created }
func newConnection(target hashname.H, addr *peerAddr, ex *e3x.Exchange, onClose func()) *connection { c := &connection{target: target, laddr: addr, raddr: addr, ex: ex, onClose: onClose} c.halfPipe = transportsutil.NewHalfPipe() return c }