change type packet from ping(1) to ping tomo(5)

This commit is contained in:
Nguyen Ba Tam 2018-09-04 16:31:08 +07:00
parent 7c55084785
commit bf5318c4c9
2 changed files with 9 additions and 8 deletions

View file

@ -59,10 +59,11 @@ const (
// RPC packet types // RPC packet types
const ( const (
pingPacket = iota + 1 // zero is 'reserved' pingPacket = iota + 1 // zero is 'reserved'
pongPacket pongPacket
findnodePacket findnodePacket
neighborsPacket neighborsPacket
pingTomo
) )
// RPC request structures // RPC request structures
@ -279,7 +280,7 @@ func (t *udp) ping(toid NodeID, toaddr *net.UDPAddr) error {
To: makeEndpoint(toaddr, 0), // TODO: maybe use known TCP port from DB To: makeEndpoint(toaddr, 0), // TODO: maybe use known TCP port from DB
Expiration: uint64(time.Now().Add(expiration).Unix()), Expiration: uint64(time.Now().Add(expiration).Unix()),
} }
packet, hash, err := encodePacket(t.priv, pingPacket, req) packet, hash, err := encodePacket(t.priv, pingTomo, req)
if err != nil { if err != nil {
return err return err
} }
@ -291,7 +292,7 @@ func (t *udp) ping(toid NodeID, toaddr *net.UDPAddr) error {
} }
func (t *udp) waitping(from NodeID) error { func (t *udp) waitping(from NodeID) error {
return <-t.pending(from, pingPacket, func(interface{}) bool { return true }) return <-t.pending(from, pingTomo, func(interface{}) bool { return true })
} }
// findnode sends a findnode request to the given node and waits until // findnode sends a findnode request to the given node and waits until
@ -563,7 +564,7 @@ func decodePacket(buf []byte) (packet, NodeID, []byte, error) {
} }
var req packet var req packet
switch ptype := sigdata[0]; ptype { switch ptype := sigdata[0]; ptype {
case pingPacket: case pingTomo:
req = new(ping) req = new(ping)
case pongPacket: case pongPacket:
req = new(pong) req = new(pong)
@ -588,14 +589,14 @@ func (req *ping) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte) er
ReplyTok: mac, ReplyTok: mac,
Expiration: uint64(time.Now().Add(expiration).Unix()), Expiration: uint64(time.Now().Add(expiration).Unix()),
}) })
if !t.handleReply(fromID, pingPacket, req) { if !t.handleReply(fromID, pingTomo, req) {
// Note: we're ignoring the provided IP address right now // Note: we're ignoring the provided IP address right now
go t.bond(true, fromID, from, req.From.TCP) go t.bond(true, fromID, from, req.From.TCP)
} }
return nil return nil
} }
func (req *ping) name() string { return "PING/v4" } func (req *ping) name() string { return "PING TOMO/v4" }
func (req *pong) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte) error { func (req *pong) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte) error {
if expired(req.Expiration) { if expired(req.Expiration) {

View file

@ -124,7 +124,7 @@ func TestUDP_packetErrors(t *testing.T) {
test := newUDPTest(t) test := newUDPTest(t)
defer test.table.Close() defer test.table.Close()
test.packetIn(errExpired, pingPacket, &ping{From: testRemote, To: testLocalAnnounced, Version: Version}) test.packetIn(errExpired, pingTomo, &ping{From: testRemote, To: testLocalAnnounced, Version: Version})
test.packetIn(errUnsolicitedReply, pongPacket, &pong{ReplyTok: []byte{}, Expiration: futureExp}) test.packetIn(errUnsolicitedReply, pongPacket, &pong{ReplyTok: []byte{}, Expiration: futureExp})
test.packetIn(errUnknownNode, findnodePacket, &findnode{Expiration: futureExp}) test.packetIn(errUnknownNode, findnodePacket, &findnode{Expiration: futureExp})
test.packetIn(errUnsolicitedReply, neighborsPacket, &neighbors{Expiration: futureExp}) test.packetIn(errUnsolicitedReply, neighborsPacket, &neighbors{Expiration: futureExp})
@ -328,7 +328,7 @@ func TestUDP_successfulPing(t *testing.T) {
defer test.table.Close() defer test.table.Close()
// The remote side sends a ping packet to initiate the exchange. // The remote side sends a ping packet to initiate the exchange.
go test.packetIn(nil, pingPacket, &ping{From: testRemote, To: testLocalAnnounced, Version: Version, Expiration: futureExp}) go test.packetIn(nil, pingTomo, &ping{From: testRemote, To: testLocalAnnounced, Version: Version, Expiration: futureExp})
// the ping is replied to. // the ping is replied to.
test.waitPacketOut(func(p *pong) { test.waitPacketOut(func(p *pong) {