Unverified Commit 6357e7c3 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #247 from libp2p/fix/64bit-ids

fix: use 64bit stream/conn IDs
parents 3d932ed9 62e792f5
......@@ -48,6 +48,9 @@ var ErrDialTimeout = errors.New("dial timed out")
// communication. The Chan sends/receives Messages, which note the
// destination or source Peer.
type Swarm struct {
nextConnID uint64 // guarded by atomic
nextStreamID uint64 // guarded by atomic
// Close refcount. This allows us to fully wait for the swarm to be torn
// down before continuing.
refs sync.WaitGroup
......@@ -55,9 +58,6 @@ type Swarm struct {
local peer.ID
peers peerstore.Peerstore
nextConnID uint32 // guarded by atomic
nextStreamID uint32 // guarded by atomic
conns struct {
sync.RWMutex
m map[peer.ID][]*Conn
......@@ -235,7 +235,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn,
conn: tc,
swarm: s,
stat: stat,
id: atomic.AddUint32(&s.nextConnID, 1),
id: atomic.AddUint64(&s.nextConnID, 1),
}
// we ONLY check upgraded connections here so we can send them a Disconnect message.
......
......@@ -25,7 +25,7 @@ var ErrConnClosed = errors.New("connection closed")
// Conn is the connection type used by swarm. In general, you won't use this
// type directly.
type Conn struct {
id uint32
id uint64
conn transport.CapableConn
swarm *Swarm
......@@ -209,7 +209,7 @@ func (c *Conn) addStream(ts mux.MuxedStream, dir network.Direction) (*Stream, er
stream: ts,
conn: c,
stat: stat,
id: atomic.AddUint32(&c.swarm.nextStreamID, 1),
id: atomic.AddUint64(&c.swarm.nextStreamID, 1),
}
c.streams.m[s] = struct{}{}
......
......@@ -17,7 +17,7 @@ var _ network.Stream = &Stream{}
// Stream is the stream type used by swarm. In general, you won't use this type
// directly.
type Stream struct {
id uint32
id uint64
stream mux.MuxedStream
conn *Conn
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment