@@ -141,15 +141,19 @@ def checkackdata(data):
141141 # bypass nonce and time, retain object type/version/stream + body
142142 readPosition = 16
143143
144- if data [readPosition :] in state .ackdataForWhichImWatching :
144+ # data may be a memoryview, which is not hashable and thus
145+ # cannot be used as a dictionary key; convert the slice to bytes.
146+ ackcheckdata = bytes (data [readPosition :])
147+
148+ if ackcheckdata in state .ackdataForWhichImWatching :
145149 logger .info ('This object is an acknowledgement bound for me.' )
146- del state .ackdataForWhichImWatching [data [ readPosition :] ]
150+ del state .ackdataForWhichImWatching [ackcheckdata ]
147151 sqlExecute (
148152 "UPDATE sent SET status='ackreceived', lastactiontime=?"
149- " WHERE ackdata=?" , int (time .time ()), data [ readPosition :] )
153+ " WHERE ackdata=?" , int (time .time ()), ackcheckdata )
150154 queues .UISignalQueue .put ((
151155 'updateSentItemStatusByAckdata' , (
152- data [ readPosition :] ,
156+ ackcheckdata ,
153157 _translate (
154158 "MainWindow" ,
155159 "Acknowledgement of the message received %1"
@@ -208,7 +212,9 @@ def processgetpubkey(data):
208212
209213 myAddress = ''
210214 if requestedAddressVersionNumber <= 3 :
211- requestedHash = data [readPosition :readPosition + 20 ]
215+ # data may be a memoryview; convert slices to bytes so they
216+ # are hashable and can be used as dictionary keys.
217+ requestedHash = bytes (data [readPosition :readPosition + 20 ])
212218 if len (requestedHash ) != 20 :
213219 return logger .debug (
214220 'The length of the requested hash is not 20 bytes.'
@@ -220,7 +226,8 @@ def processgetpubkey(data):
220226 if requestedHash in shared .myAddressesByHash :
221227 myAddress = shared .myAddressesByHash [requestedHash ]
222228 elif requestedAddressVersionNumber >= 4 :
223- requestedTag = data [readPosition :readPosition + 32 ]
229+ # data may be a memoryview; convert to bytes for hashability.
230+ requestedTag = bytes (data [readPosition :readPosition + 32 ])
224231 if len (requestedTag ) != 32 :
225232 return logger .debug (
226233 'The length of the requested tag is not 32 bytes.'
@@ -413,7 +420,8 @@ def processpubkey(self, data):
413420 '(within processpubkey) payloadLength less than 350.'
414421 ' Sanity check failed.' )
415422
416- tag = data [readPosition :readPosition + 32 ]
423+ # data may be a memoryview; convert to bytes for hashability.
424+ tag = bytes (data [readPosition :readPosition + 32 ])
417425 if tag not in state .neededPubkeys :
418426 return logger .info (
419427 'We don\' t need this v4 pubkey. We didn\' t ask for it.' )
@@ -807,7 +815,8 @@ def processbroadcast(self, data):
807815 ' v4 broadcast: %s seconds.' ,
808816 time .time () - messageProcessingStartTime )
809817 elif broadcastVersion == 5 :
810- embeddedTag = data [readPosition :readPosition + 32 ]
818+ # data may be a memoryview; convert to bytes for hashability.
819+ embeddedTag = bytes (data [readPosition :readPosition + 32 ])
811820 readPosition += 32
812821 if embeddedTag not in shared .MyECSubscriptionCryptorObjects :
813822 logger .debug ('We\' re not interested in this broadcast.' )
0 commit comments