Skip to content

Commit

Permalink
Rename Version message to Handshake (#2479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine committed Dec 22, 2023
1 parent 7e5d1a2 commit 5ebafd9
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 426 deletions.
30 changes: 15 additions & 15 deletions message/messages_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ var (
dummyOnFinishedHandling = func() {}
)

// Benchmarks marshal-ing "Version" message.
// Benchmarks marshal-ing "Handshake" message.
//
// e.g.,
//
// $ go install -v golang.org/x/tools/cmd/benchcmp@latest
// $ go install -v golang.org/x/perf/cmd/benchstat@latest
//
// $ go test -run=NONE -bench=BenchmarkMarshalVersion > /tmp/cpu.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkMarshalVersion > /tmp/cpu.after.txt
// $ go test -run=NONE -bench=BenchmarkMarshalHandshake > /tmp/cpu.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkMarshalHandshake > /tmp/cpu.after.txt
// $ benchcmp /tmp/cpu.before.txt /tmp/cpu.after.txt
// $ benchstat -alpha 0.03 -geomean /tmp/cpu.before.txt /tmp/cpu.after.txt
//
// $ go test -run=NONE -bench=BenchmarkMarshalVersion -benchmem > /tmp/mem.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkMarshalVersion -benchmem > /tmp/mem.after.txt
// $ go test -run=NONE -bench=BenchmarkMarshalHandshake -benchmem > /tmp/mem.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkMarshalHandshake -benchmem > /tmp/mem.after.txt
// $ benchcmp /tmp/mem.before.txt /tmp/mem.after.txt
// $ benchstat -alpha 0.03 -geomean /tmp/mem.before.txt /tmp/mem.after.txt
func BenchmarkMarshalVersion(b *testing.B) {
func BenchmarkMarshalHandshake(b *testing.B) {
require := require.New(b)

id := ids.GenerateTestID()
msg := p2p.Message{
Message: &p2p.Message_Version{
Version: &p2p.Version{
Message: &p2p.Message_Handshake{
Handshake: &p2p.Handshake{
NetworkId: uint32(1337),
MyTime: uint64(time.Now().Unix()),
IpAddr: []byte(net.IPv4(1, 2, 3, 4).To16()),
Expand Down Expand Up @@ -87,24 +87,24 @@ func BenchmarkMarshalVersion(b *testing.B) {
// $ go install -v golang.org/x/tools/cmd/benchcmp@latest
// $ go install -v golang.org/x/perf/cmd/benchstat@latest
//
// $ go test -run=NONE -bench=BenchmarkUnmarshalVersion > /tmp/cpu.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkUnmarshalVersion > /tmp/cpu.after.txt
// $ go test -run=NONE -bench=BenchmarkUnmarshalHandshake > /tmp/cpu.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkUnmarshalHandshake > /tmp/cpu.after.txt
// $ benchcmp /tmp/cpu.before.txt /tmp/cpu.after.txt
// $ benchstat -alpha 0.03 -geomean /tmp/cpu.before.txt /tmp/cpu.after.txt
//
// $ go test -run=NONE -bench=BenchmarkUnmarshalVersion -benchmem > /tmp/mem.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkUnmarshalVersion -benchmem > /tmp/mem.after.txt
// $ go test -run=NONE -bench=BenchmarkUnmarshalHandshake -benchmem > /tmp/mem.before.txt
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkUnmarshalHandshake -benchmem > /tmp/mem.after.txt
// $ benchcmp /tmp/mem.before.txt /tmp/mem.after.txt
// $ benchstat -alpha 0.03 -geomean /tmp/mem.before.txt /tmp/mem.after.txt
func BenchmarkUnmarshalVersion(b *testing.B) {
func BenchmarkUnmarshalHandshake(b *testing.B) {
require := require.New(b)

b.StopTimer()

id := ids.GenerateTestID()
msg := p2p.Message{
Message: &p2p.Message_Version{
Version: &p2p.Version{
Message: &p2p.Message_Handshake{
Handshake: &p2p.Handshake{
NetworkId: uint32(1337),
MyTime: uint64(time.Now().Unix()),
IpAddr: []byte(net.IPv4(1, 2, 3, 4).To16()),
Expand Down
8 changes: 4 additions & 4 deletions message/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ func TestMessage(t *testing.T) {
bytesSaved: false,
},
{
desc: "version message with no compression",
op: VersionOp,
desc: "Handshake message with no compression",
op: HandshakeOp,
msg: &p2p.Message{
Message: &p2p.Message_Version{
Version: &p2p.Version{
Message: &p2p.Message_Handshake{
Handshake: &p2p.Handshake{
NetworkId: uint32(1337),
MyTime: uint64(nowUnix),
IpAddr: []byte(net.IPv6zero),
Expand Down
30 changes: 15 additions & 15 deletions message/mock_outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions message/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
// Handshake:
PingOp Op = iota
PongOp
VersionOp
HandshakeOp
PeerListOp
PeerListAckOp
// State sync:
Expand Down Expand Up @@ -71,7 +71,7 @@ var (
HandshakeOps = []Op{
PingOp,
PongOp,
VersionOp,
HandshakeOp,
PeerListOp,
PeerListAckOp,
}
Expand Down Expand Up @@ -209,8 +209,8 @@ func (op Op) String() string {
return "ping"
case PongOp:
return "pong"
case VersionOp:
return "version"
case HandshakeOp:
return "handshake"
case PeerListOp:
return "peerlist"
case PeerListAckOp:
Expand Down Expand Up @@ -303,8 +303,8 @@ func Unwrap(m *p2p.Message) (fmt.Stringer, error) {
return msg.Ping, nil
case *p2p.Message_Pong:
return msg.Pong, nil
case *p2p.Message_Version:
return msg.Version, nil
case *p2p.Message_Handshake:
return msg.Handshake, nil
case *p2p.Message_PeerList:
return msg.PeerList, nil
case *p2p.Message_PeerListAck:
Expand Down Expand Up @@ -362,8 +362,8 @@ func ToOp(m *p2p.Message) (Op, error) {
return PingOp, nil
case *p2p.Message_Pong:
return PongOp, nil
case *p2p.Message_Version:
return VersionOp, nil
case *p2p.Message_Handshake:
return HandshakeOp, nil
case *p2p.Message_PeerList:
return PeerListOp, nil
case *p2p.Message_PeerListAck:
Expand Down
8 changes: 4 additions & 4 deletions message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ OutboundMsgBuilder = (*outMsgBuilder)(nil)
// with a reference count of 1. Once the reference count hits 0, the message
// bytes should no longer be accessed.
type OutboundMsgBuilder interface {
Version(
Handshake(
networkID uint32,
myTime uint64,
ip ips.IPPort,
Expand Down Expand Up @@ -230,7 +230,7 @@ func (b *outMsgBuilder) Pong(
)
}

func (b *outMsgBuilder) Version(
func (b *outMsgBuilder) Handshake(
networkID uint32,
myTime uint64,
ip ips.IPPort,
Expand All @@ -249,8 +249,8 @@ func (b *outMsgBuilder) Version(
encodeIDs(trackedSubnets, subnetIDBytes)
return b.builder.createOutbound(
&p2p.Message{
Message: &p2p.Message_Version{
Version: &p2p.Version{
Message: &p2p.Message_Handshake{
Handshake: &p2p.Handshake{
NetworkId: networkID,
MyTime: myTime,
IpAddr: ip.IP.To16(),
Expand Down
12 changes: 6 additions & 6 deletions network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ In Avalanche, nodes connect to an initial set of bootstrapper nodes known as **b

Upon connection to any peer, a handshake is performed between the node attempting to establish the outbound connection to the peer and the peer receiving the inbound connection.

When attempting to establish the connection, the first message that the node attempting to connect to the peer in the network is a `Version` message describing compatibility of the candidate node with the peer. As an example, nodes that are attempting to connect with an incompatible version of AvalancheGo or a significantly skewed local clock are rejected by the peer.
When attempting to establish the connection, the first message that the node attempting to connect to the peer in the network is a `Handshake` message describing compatibility of the candidate node with the peer. As an example, nodes that are attempting to connect with an incompatible version of AvalancheGo or a significantly skewed local clock are rejected by the peer.

```mermaid
sequenceDiagram
Note over Node,Peer: Initiate Handshake
Note left of Node: I want to connect to you!
Note over Node,Peer: Version message
Note over Node,Peer: Handshake message
Node->>Peer: AvalancheGo v1.0.0
Note right of Peer: My version v1.9.4 is incompatible with your version v1.0.0.
Peer-xNode: Connection dropped
Note over Node,Peer: Handshake Failed
```

If the `Version` message is successfully received and the peer decides that it wants a connection with this node, it replies with a `PeerList` message that contains metadata about other peers that allows a node to connect to them. Upon reception of a `PeerList` message, a node will attempt to connect to any peers that the node is not already connected to to allow the node to discover more peers in the network.
If the `Handshake` message is successfully received and the peer decides that it wants a connection with this node, it replies with a `PeerList` message that contains metadata about other peers that allows a node to connect to them. Upon reception of a `PeerList` message, a node will attempt to connect to any peers that the node is not already connected to to allow the node to discover more peers in the network.

```mermaid
sequenceDiagram
Note over Node,Peer: Initiate Handshake
Note left of Node: I want to connect to you!
Note over Node,Peer: Version message
Note over Node,Peer: Handshake message
Node->>Peer: AvalancheGo v1.9.4
Note right of Peer: LGTM!
Note over Node,Peer: PeerList message
Expand All @@ -90,11 +90,11 @@ Some peers aren't discovered through the `PeerList` messages exchanged through p

```mermaid
sequenceDiagram
Node ->> Peer-1: Version - v1.9.5
Node ->> Peer-1: Handshake - v1.9.5
Peer-1 ->> Node: PeerList - Peer-2
Node ->> Peer-1: ACK - Peer-2
Note left of Node: Node is connected to Peer-1 and now tries to connect to Peer-2.
Node ->> Peer-2: Version - v1.9.5
Node ->> Peer-2: Handshake - v1.9.5
Peer-2 ->> Node: PeerList - Peer-1
Node ->> Peer-2: ACK - Peer-1
Note left of Node: Peer-3 was never sampled, so we haven't connected yet!
Expand Down
2 changes: 1 addition & 1 deletion network/peer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ type Config struct {
// Calculates uptime of peers
UptimeCalculator uptime.Calculator

// Signs my IP so I can send my signed IP address in the Version message
// Signs my IP so I can send my signed IP address in the Handshake message
IPSigner *IPSigner
}
Loading

0 comments on commit 5ebafd9

Please sign in to comment.