@@ -61,6 +61,10 @@ const (
61
61
dbVersion = 9
62
62
)
63
63
64
+ var (
65
+ errInvalidIP = errors .New ("invalid IP" )
66
+ )
67
+
64
68
var zeroIP = make (net.IP , 16 )
65
69
66
70
// DB is the node database, storing previously seen nodes and any collected metadata about
@@ -359,43 +363,67 @@ func (db *DB) expireNodes() {
359
363
// LastPingReceived retrieves the time of the last ping packet received from
360
364
// a remote node.
361
365
func (db * DB ) LastPingReceived (id ID , ip net.IP ) time.Time {
366
+ if ip = ip .To16 (); ip == nil {
367
+ return time.Time {}
368
+ }
362
369
return time .Unix (db .fetchInt64 (nodeItemKey (id , ip , dbNodePing )), 0 )
363
370
}
364
371
365
372
// UpdateLastPingReceived updates the last time we tried contacting a remote node.
366
373
func (db * DB ) UpdateLastPingReceived (id ID , ip net.IP , instance time.Time ) error {
374
+ if ip = ip .To16 (); ip == nil {
375
+ return errInvalidIP
376
+ }
367
377
return db .storeInt64 (nodeItemKey (id , ip , dbNodePing ), instance .Unix ())
368
378
}
369
379
370
380
// LastPongReceived retrieves the time of the last successful pong from remote node.
371
381
func (db * DB ) LastPongReceived (id ID , ip net.IP ) time.Time {
382
+ if ip = ip .To16 (); ip == nil {
383
+ return time.Time {}
384
+ }
372
385
// Launch expirer
373
386
db .ensureExpirer ()
374
387
return time .Unix (db .fetchInt64 (nodeItemKey (id , ip , dbNodePong )), 0 )
375
388
}
376
389
377
390
// UpdateLastPongReceived updates the last pong time of a node.
378
391
func (db * DB ) UpdateLastPongReceived (id ID , ip net.IP , instance time.Time ) error {
392
+ if ip = ip .To16 (); ip == nil {
393
+ return errInvalidIP
394
+ }
379
395
return db .storeInt64 (nodeItemKey (id , ip , dbNodePong ), instance .Unix ())
380
396
}
381
397
382
398
// FindFails retrieves the number of findnode failures since bonding.
383
399
func (db * DB ) FindFails (id ID , ip net.IP ) int {
400
+ if ip = ip .To16 (); ip == nil {
401
+ return 0
402
+ }
384
403
return int (db .fetchInt64 (nodeItemKey (id , ip , dbNodeFindFails )))
385
404
}
386
405
387
406
// UpdateFindFails updates the number of findnode failures since bonding.
388
407
func (db * DB ) UpdateFindFails (id ID , ip net.IP , fails int ) error {
408
+ if ip = ip .To16 (); ip == nil {
409
+ return errInvalidIP
410
+ }
389
411
return db .storeInt64 (nodeItemKey (id , ip , dbNodeFindFails ), int64 (fails ))
390
412
}
391
413
392
414
// FindFailsV5 retrieves the discv5 findnode failure counter.
393
415
func (db * DB ) FindFailsV5 (id ID , ip net.IP ) int {
416
+ if ip = ip .To16 (); ip == nil {
417
+ return 0
418
+ }
394
419
return int (db .fetchInt64 (v5Key (id , ip , dbNodeFindFails )))
395
420
}
396
421
397
422
// UpdateFindFailsV5 stores the discv5 findnode failure counter.
398
423
func (db * DB ) UpdateFindFailsV5 (id ID , ip net.IP , fails int ) error {
424
+ if ip = ip .To16 (); ip == nil {
425
+ return errInvalidIP
426
+ }
399
427
return db .storeInt64 (v5Key (id , ip , dbNodeFindFails ), int64 (fails ))
400
428
}
401
429
0 commit comments