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