Skip to content

Commit

Permalink
change type packet from ping(1) to ping tomo(5)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenbatam committed Sep 4, 2018
1 parent 7c55084 commit bf5318c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions p2p/discover/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ const (

// RPC packet types
const (
pingPacket = iota + 1 // zero is 'reserved'
pingPacket = iota + 1 // zero is 'reserved'
pongPacket
findnodePacket
neighborsPacket
pingTomo
)

// RPC request structures
Expand Down Expand Up @@ -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
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 {
return err
}
Expand All @@ -291,7 +292,7 @@ func (t *udp) ping(toid NodeID, toaddr *net.UDPAddr) 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
Expand Down Expand Up @@ -563,7 +564,7 @@ func decodePacket(buf []byte) (packet, NodeID, []byte, error) {
}
var req packet
switch ptype := sigdata[0]; ptype {
case pingPacket:
case pingTomo:
req = new(ping)
case pongPacket:
req = new(pong)
Expand All @@ -588,14 +589,14 @@ func (req *ping) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte) er
ReplyTok: mac,
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
go t.bond(true, fromID, from, req.From.TCP)
}
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 {
if expired(req.Expiration) {
Expand Down
4 changes: 2 additions & 2 deletions p2p/discover/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestUDP_packetErrors(t *testing.T) {
test := newUDPTest(t)
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(errUnknownNode, findnodePacket, &findnode{Expiration: futureExp})
test.packetIn(errUnsolicitedReply, neighborsPacket, &neighbors{Expiration: futureExp})
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestUDP_successfulPing(t *testing.T) {
defer test.table.Close()

// 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.
test.waitPacketOut(func(p *pong) {
Expand Down

0 comments on commit bf5318c

Please sign in to comment.