Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit b58b10e

Browse files
hoffmabcplacer14
authored andcommitted
Clarify offline message logging messages
1 parent 03c9055 commit b58b10e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

net/retriever/retriever.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,14 @@ func (m *MessageRetriever) fetchIPFS(pid peer.ID, n *core.IpfsNode, addr ma.Mult
246246
select {
247247
case <-c:
248248
if err != nil {
249-
log.Errorf("Error retrieving offline message from %s, %s", addr.String(), err.Error())
249+
log.Errorf("Error retrieving offline message from: %s, Error: %s", addr.String(), err.Error())
250250
return
251251
}
252-
log.Debugf("Successfully downloaded offline message from %s", addr.String())
253-
m.db.OfflineMessages().Put(addr.String())
252+
log.Debugf("Successfully downloaded offline message %s from: %s", addr.String(), pid.Pretty())
253+
err = m.db.OfflineMessages().Put(addr.String())
254+
if err != nil {
255+
log.Error(err)
256+
}
254257
m.attemptDecrypt(ciphertext, pid, addr)
255258
case <-m.DoneChan:
256259
return
@@ -302,44 +305,46 @@ func (m *MessageRetriever) attemptDecrypt(ciphertext []byte, pid peer.ID, addr m
302305
// Decrypt and unmarshal plaintext
303306
plaintext, err := net.Decrypt(m.node.PrivateKey, ciphertext)
304307
if err != nil {
305-
log.Warningf("Unable to decrypt offline message from %s: %s", addr.String(), err.Error())
308+
log.Warningf("Unable to decrypt cipher text to plain text, CID: %s: Error:%s\n", addr.String(), err.Error())
306309
return
307310
}
308311

309312
// Unmarshal plaintext
310313
env := pb.Envelope{}
311314
err = proto.Unmarshal(plaintext, &env)
312315
if err != nil {
313-
log.Warningf("Unable to decrypt offline message from %s: %s", addr.String(), err.Error())
316+
log.Warningf("Unable to unmarshal plaintext to encrypted Envelope, CID: %s: Error:%s\n", addr.String(), err.Error())
314317
return
315318
}
316319

317320
// Validate the signature
318321
ser, err := proto.Marshal(env.Message)
319322
if err != nil {
320-
log.Warningf("Unable to decrypt offline message from %s: %s", addr.String(), err.Error())
323+
log.Warningf("Unable to serialize the encrypted message, CID: %s: Error:%s\n", addr.String(), err.Error())
321324
return
322325
}
323326
pubkey, err := libp2p.UnmarshalPublicKey(env.Pubkey)
324327
if err != nil {
325-
log.Warningf("Unable to decrypt offline message from %s: %s", addr.String(), err.Error())
328+
log.Warningf("Unable to unmarshal the public key from, CID: %s: Error:%s\n", addr.String(), err.Error())
326329
return
327330
}
328331

329332
valid, err := pubkey.Verify(ser, env.Signature)
330333
if err != nil || !valid {
331-
log.Warningf("Unable to decrypt offline message from %s: %s", addr.String(), err.Error())
334+
log.Warningf("Unable to verify message signature, CID: %s: Error:%s\n", addr.String(), err.Error())
332335
return
333336
}
334337

335338
id, err := peer.IDFromPublicKey(pubkey)
336339
if err != nil {
337-
log.Warningf("Unable to decrypt offline message from %s: %s", addr.String(), err.Error())
340+
log.Warningf("Unable to get a peer ID from the pubkey, CID: %s: Error:%s\n", addr.String(), err.Error())
338341
return
339342
}
340343

344+
log.Debugf("Received offline message %s from: %s\n", addr.String(), id.Pretty())
345+
341346
if m.bm.IsBanned(id) {
342-
log.Warningf("Received and dropped offline message from banned user: %s ", id.String())
347+
log.Warningf("Received and dropped offline message from banned user: %s\n", id.Pretty())
343348
return
344349
}
345350

0 commit comments

Comments
 (0)