35
35
limit_peers = None
36
36
37
37
SEC_TYPES_SELF = (10 , )
38
- SEC_TYPES_PEER = (1 , 2 , 3 , 4 )
39
-
38
+ SEC_TYPES_PEER = (1 , 2 , 4 )
39
+ SEC_TYPES_CCCD = ( 3 , )
40
40
41
41
# Must call this before stack startup.
42
42
def load_secrets (path = None ):
@@ -105,14 +105,16 @@ def _save_secrets(arg=None):
105
105
_modified = False
106
106
107
107
108
- def _remove_entry (sec_type , key ):
108
+ def _remove_entry (sec_type , key , value = None ):
109
109
secrets = _secrets [sec_type ]
110
110
111
111
# Delete existing secrets matching the type and key.
112
112
deleted = False
113
113
for to_delete in [
114
114
entry for entry in secrets if entry [0 ] == key
115
115
]:
116
+ if value and to_delete [1 ] != value :
117
+ continue
116
118
log_info ("Removing existing secret matching key" )
117
119
secrets .remove (to_delete )
118
120
deleted = True
@@ -124,7 +126,7 @@ def _log_peers(heading=""):
124
126
if core .log_level <= 2 :
125
127
return
126
128
log_info ("secrets:" , heading )
127
- for sec_type in SEC_TYPES_PEER :
129
+ for sec_type in SEC_TYPES_PEER + SEC_TYPES_CCCD :
128
130
log_info ("-" , sec_type )
129
131
130
132
if sec_type not in _secrets :
@@ -171,8 +173,13 @@ def _security_irq(event, data):
171
173
_secrets [sec_type ] = []
172
174
secrets = _secrets [sec_type ]
173
175
174
- # Delete existing secrets matching the type and key.
175
- removed = _remove_entry (sec_type , key )
176
+ # Delete existing secrets matching the type and key as required.
177
+ # There should only every be one SEC_TYPES_PEER per addr, but
178
+ # multiple entries are allowed for SEC_TYPES_CCCD
179
+ del_by_value = None
180
+ if not is_deleting and sec_type in SEC_TYPES_CCCD :
181
+ del_by_value = value
182
+ removed = _remove_entry (sec_type , key , del_by_value )
176
183
177
184
if is_deleting and not removed :
178
185
# Delete mode, but no entries were deleted
@@ -216,6 +223,9 @@ def _security_irq(event, data):
216
223
217
224
for k , v in secrets :
218
225
if k == key :
226
+ if index :
227
+ index -= 1
228
+ continue
219
229
return v
220
230
return None
221
231
0 commit comments