Commit 1fd68ed7 authored by Steven Allen's avatar Steven Allen

sessionmanager: allow concurrent receive/wanted checks

parent 863aa22c
...@@ -46,7 +46,7 @@ type SessionManager struct { ...@@ -46,7 +46,7 @@ type SessionManager struct {
notif notifications.PubSub notif notifications.PubSub
// Sessions // Sessions
sessLk sync.Mutex sessLk sync.RWMutex
sessions []sesTrk sessions []sesTrk
// Session Index // Session Index
...@@ -117,8 +117,8 @@ func (sm *SessionManager) GetNextSessionID() uint64 { ...@@ -117,8 +117,8 @@ func (sm *SessionManager) GetNextSessionID() uint64 {
// ReceiveFrom receives block CIDs from a peer and dispatches to sessions. // ReceiveFrom receives block CIDs from a peer and dispatches to sessions.
func (sm *SessionManager) ReceiveFrom(from peer.ID, ks []cid.Cid) { func (sm *SessionManager) ReceiveFrom(from peer.ID, ks []cid.Cid) {
sm.sessLk.Lock() sm.sessLk.RLock()
defer sm.sessLk.Unlock() defer sm.sessLk.RUnlock()
for _, s := range sm.sessions { for _, s := range sm.sessions {
s.session.ReceiveFrom(from, ks) s.session.ReceiveFrom(from, ks)
...@@ -128,8 +128,8 @@ func (sm *SessionManager) ReceiveFrom(from peer.ID, ks []cid.Cid) { ...@@ -128,8 +128,8 @@ func (sm *SessionManager) ReceiveFrom(from peer.ID, ks []cid.Cid) {
// IsWanted indicates whether any of the sessions are waiting to receive // IsWanted indicates whether any of the sessions are waiting to receive
// the block with the given CID. // the block with the given CID.
func (sm *SessionManager) IsWanted(cid cid.Cid) bool { func (sm *SessionManager) IsWanted(cid cid.Cid) bool {
sm.sessLk.Lock() sm.sessLk.RLock()
defer sm.sessLk.Unlock() defer sm.sessLk.RUnlock()
for _, s := range sm.sessions { for _, s := range sm.sessions {
if s.session.IsWanted(cid) { if s.session.IsWanted(cid) {
......
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