@@ -93,27 +93,9 @@ func (a *accessMan) assignPeerPerms(remotePub *btcec.PublicKey) (
93
93
// Default is restricted unless the below filters say otherwise.
94
94
access := peerStatusRestricted
95
95
96
- shouldDisconnect , err := a .cfg .shouldDisconnect (remotePub )
97
- if err != nil {
98
- acsmLog .ErrorS (ctx , "Error checking disconnect status" , err )
99
-
100
- // Access is restricted here.
101
- return access , err
102
- }
103
-
104
- if shouldDisconnect {
105
- acsmLog .WarnS (ctx , "Peer is banned, assigning restricted access" ,
106
- ErrGossiperBan )
107
-
108
- // Access is restricted here.
109
- return access , ErrGossiperBan
110
- }
111
-
112
96
// Lock banScoreMtx for reading so that we can update the banning maps
113
97
// below.
114
98
a .banScoreMtx .RLock ()
115
- defer a .banScoreMtx .RUnlock ()
116
-
117
99
if count , found := a .peerCounts [peerMapKey ]; found {
118
100
if count .HasOpenOrClosedChan {
119
101
acsmLog .DebugS (ctx , "Peer has open/closed channel, " +
@@ -127,23 +109,45 @@ func (a *accessMan) assignPeerPerms(remotePub *btcec.PublicKey) (
127
109
access = peerStatusTemporary
128
110
}
129
111
}
112
+ a .banScoreMtx .RUnlock ()
113
+
114
+ // Exit early if the peer status is no longer restricted.
115
+ if access != peerStatusRestricted {
116
+ return access , nil
117
+ }
118
+
119
+ // Check whether this peer is banned.
120
+ shouldDisconnect , err := a .cfg .shouldDisconnect (remotePub )
121
+ if err != nil {
122
+ acsmLog .ErrorS (ctx , "Error checking disconnect status" , err )
123
+
124
+ // Access is restricted here.
125
+ return access , err
126
+ }
127
+
128
+ if shouldDisconnect {
129
+ acsmLog .WarnS (ctx , "Peer is banned, assigning restricted access" ,
130
+ ErrGossiperBan )
131
+
132
+ // Access is restricted here.
133
+ return access , ErrGossiperBan
134
+ }
130
135
131
136
// If we've reached this point and access hasn't changed from
132
137
// restricted, then we need to check if we even have a slot for this
133
138
// peer.
134
- if access == peerStatusRestricted {
135
- acsmLog .DebugS (ctx , "Peer has no channels, assigning " +
136
- "restricted access" )
139
+ acsmLog .DebugS (ctx , "Peer has no channels, assigning restricted access" )
137
140
138
- if a .numRestricted >= a .cfg .maxRestrictedSlots {
139
- acsmLog .WarnS (ctx , "No more restricted slots " +
140
- "available, denying peer" ,
141
- ErrNoMoreRestrictedAccessSlots ,
142
- "num_restricted" , a .numRestricted ,
143
- "max_restricted" , a .cfg .maxRestrictedSlots )
141
+ a .banScoreMtx .RLock ()
142
+ defer a .banScoreMtx .RUnlock ()
144
143
145
- return access , ErrNoMoreRestrictedAccessSlots
146
- }
144
+ if a .numRestricted >= a .cfg .maxRestrictedSlots {
145
+ acsmLog .WarnS (ctx , "No more restricted slots available, " +
146
+ "denying peer" , ErrNoMoreRestrictedAccessSlots ,
147
+ "num_restricted" , a .numRestricted , "max_restricted" ,
148
+ a .cfg .maxRestrictedSlots )
149
+
150
+ return access , ErrNoMoreRestrictedAccessSlots
147
151
}
148
152
149
153
return access , nil
0 commit comments