mirror of https://github.com/poanetwork/gecko.git
Merge pull request #55 from ava-labs/ping-pong
Added ping pong messages
This commit is contained in:
commit
be5957875c
|
@ -50,6 +50,122 @@ func (c *Config) init() error {
|
||||||
|
|
||||||
// Hard coded genesis constants
|
// Hard coded genesis constants
|
||||||
var (
|
var (
|
||||||
|
EverestConfig = Config{
|
||||||
|
MintAddresses: []string{
|
||||||
|
"95YUFjhDG892VePMzpwKF9JzewGKvGRi3",
|
||||||
|
},
|
||||||
|
FundedAddresses: []string{
|
||||||
|
"9uKvvA7E35QCwLvAaohXTCfFejbf3Rv17",
|
||||||
|
"JLrYNMYXANGj43BfWXBxMMAEenUBp1Sbn",
|
||||||
|
"7TUTzwrU6nbZtWHjTHEpdneUvjKBxb3EM",
|
||||||
|
"77mPUXBdQKwQpPoX6rckCZGLGGdkuG1G6",
|
||||||
|
"4gGWdFZ4Gax1B466YKXyKRRpWLb42Afdt",
|
||||||
|
"CKTkzAPsRxCreyiDTnjGxLmjMarxF28fi",
|
||||||
|
"4ABm9gFHVtsNdcKSd1xsacFkGneSgzpaa",
|
||||||
|
"DpL8PTsrjtLzv5J8LL3D2A6YcnCTqrNH9",
|
||||||
|
"ZdhZv6oZrmXLyFDy6ovXAu6VxmbTsT2h",
|
||||||
|
"6cesTteH62Y5mLoDBUASaBvCXuL2AthL",
|
||||||
|
},
|
||||||
|
StakerIDs: []string{
|
||||||
|
"LQwRLm4cbJ7T2kxcxp4uXCU5XD8DFrE1C",
|
||||||
|
"hArafGhY2HFTbwaaVh1CSCUCUCiJ2Vfb",
|
||||||
|
"2m38qc95mhHXtrhjyGbe7r2NhniqHHJRB",
|
||||||
|
"4QBwET5o8kUhvt9xArhir4d3R25CtmZho",
|
||||||
|
"NpagUxt6KQiwPch9Sd4osv8kD1TZnkjdk",
|
||||||
|
},
|
||||||
|
EVMBytes: []byte{
|
||||||
|
0x7b, 0x22, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
|
||||||
|
0x22, 0x3a, 0x7b, 0x22, 0x63, 0x68, 0x61, 0x69,
|
||||||
|
0x6e, 0x49, 0x64, 0x22, 0x3a, 0x34, 0x33, 0x31,
|
||||||
|
0x31, 0x30, 0x2c, 0x22, 0x68, 0x6f, 0x6d, 0x65,
|
||||||
|
0x73, 0x74, 0x65, 0x61, 0x64, 0x42, 0x6c, 0x6f,
|
||||||
|
0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x64,
|
||||||
|
0x61, 0x6f, 0x46, 0x6f, 0x72, 0x6b, 0x42, 0x6c,
|
||||||
|
0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22,
|
||||||
|
0x64, 0x61, 0x6f, 0x46, 0x6f, 0x72, 0x6b, 0x53,
|
||||||
|
0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x3a,
|
||||||
|
0x74, 0x72, 0x75, 0x65, 0x2c, 0x22, 0x65, 0x69,
|
||||||
|
0x70, 0x31, 0x35, 0x30, 0x42, 0x6c, 0x6f, 0x63,
|
||||||
|
0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x65, 0x69,
|
||||||
|
0x70, 0x31, 0x35, 0x30, 0x48, 0x61, 0x73, 0x68,
|
||||||
|
0x22, 0x3a, 0x22, 0x30, 0x78, 0x32, 0x30, 0x38,
|
||||||
|
0x36, 0x37, 0x39, 0x39, 0x61, 0x65, 0x65, 0x62,
|
||||||
|
0x65, 0x61, 0x65, 0x31, 0x33, 0x35, 0x63, 0x32,
|
||||||
|
0x34, 0x36, 0x63, 0x36, 0x35, 0x30, 0x32, 0x31,
|
||||||
|
0x63, 0x38, 0x32, 0x62, 0x34, 0x65, 0x31, 0x35,
|
||||||
|
0x61, 0x32, 0x63, 0x34, 0x35, 0x31, 0x33, 0x34,
|
||||||
|
0x30, 0x39, 0x39, 0x33, 0x61, 0x61, 0x63, 0x66,
|
||||||
|
0x64, 0x32, 0x37, 0x35, 0x31, 0x38, 0x38, 0x36,
|
||||||
|
0x35, 0x31, 0x34, 0x66, 0x30, 0x22, 0x2c, 0x22,
|
||||||
|
0x65, 0x69, 0x70, 0x31, 0x35, 0x35, 0x42, 0x6c,
|
||||||
|
0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22,
|
||||||
|
0x65, 0x69, 0x70, 0x31, 0x35, 0x38, 0x42, 0x6c,
|
||||||
|
0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22,
|
||||||
|
0x62, 0x79, 0x7a, 0x61, 0x6e, 0x74, 0x69, 0x75,
|
||||||
|
0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3a,
|
||||||
|
0x30, 0x2c, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74,
|
||||||
|
0x61, 0x6e, 0x74, 0x69, 0x6e, 0x6f, 0x70, 0x6c,
|
||||||
|
0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3a,
|
||||||
|
0x30, 0x2c, 0x22, 0x70, 0x65, 0x74, 0x65, 0x72,
|
||||||
|
0x73, 0x62, 0x75, 0x72, 0x67, 0x42, 0x6c, 0x6f,
|
||||||
|
0x63, 0x6b, 0x22, 0x3a, 0x30, 0x7d, 0x2c, 0x22,
|
||||||
|
0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x22,
|
||||||
|
0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, 0x74, 0x69,
|
||||||
|
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22,
|
||||||
|
0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22,
|
||||||
|
0x65, 0x78, 0x74, 0x72, 0x61, 0x44, 0x61, 0x74,
|
||||||
|
0x61, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, 0x30,
|
||||||
|
0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x4c, 0x69,
|
||||||
|
0x6d, 0x69, 0x74, 0x22, 0x3a, 0x22, 0x30, 0x78,
|
||||||
|
0x35, 0x66, 0x35, 0x65, 0x31, 0x30, 0x30, 0x22,
|
||||||
|
0x2c, 0x22, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63,
|
||||||
|
0x75, 0x6c, 0x74, 0x79, 0x22, 0x3a, 0x22, 0x30,
|
||||||
|
0x78, 0x30, 0x22, 0x2c, 0x22, 0x6d, 0x69, 0x78,
|
||||||
|
0x48, 0x61, 0x73, 0x68, 0x22, 0x3a, 0x22, 0x30,
|
||||||
|
0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f, 0x69, 0x6e,
|
||||||
|
0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x30,
|
||||||
|
0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x22, 0x2c, 0x22, 0x61, 0x6c, 0x6c, 0x6f,
|
||||||
|
0x63, 0x22, 0x3a, 0x7b, 0x22, 0x35, 0x37, 0x32,
|
||||||
|
0x66, 0x34, 0x64, 0x38, 0x30, 0x66, 0x31, 0x30,
|
||||||
|
0x66, 0x36, 0x36, 0x33, 0x62, 0x35, 0x30, 0x34,
|
||||||
|
0x39, 0x66, 0x37, 0x38, 0x39, 0x35, 0x34, 0x36,
|
||||||
|
0x66, 0x32, 0x35, 0x66, 0x37, 0x30, 0x62, 0x62,
|
||||||
|
0x36, 0x32, 0x61, 0x37, 0x66, 0x22, 0x3a, 0x7b,
|
||||||
|
0x22, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65,
|
||||||
|
0x22, 0x3a, 0x22, 0x30, 0x78, 0x33, 0x33, 0x62,
|
||||||
|
0x32, 0x65, 0x33, 0x63, 0x39, 0x66, 0x64, 0x30,
|
||||||
|
0x38, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x22, 0x7d, 0x7d, 0x2c,
|
||||||
|
0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22,
|
||||||
|
0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22,
|
||||||
|
0x67, 0x61, 0x73, 0x55, 0x73, 0x65, 0x64, 0x22,
|
||||||
|
0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22,
|
||||||
|
0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x61,
|
||||||
|
0x73, 0x68, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22,
|
||||||
|
0x7d,
|
||||||
|
},
|
||||||
|
}
|
||||||
DenaliConfig = Config{
|
DenaliConfig = Config{
|
||||||
MintAddresses: []string{
|
MintAddresses: []string{
|
||||||
"95YUFjhDG892VePMzpwKF9JzewGKvGRi3",
|
"95YUFjhDG892VePMzpwKF9JzewGKvGRi3",
|
||||||
|
@ -393,6 +509,8 @@ var (
|
||||||
// GetConfig ...
|
// GetConfig ...
|
||||||
func GetConfig(networkID uint32) *Config {
|
func GetConfig(networkID uint32) *Config {
|
||||||
switch networkID {
|
switch networkID {
|
||||||
|
case EverestID:
|
||||||
|
return &EverestConfig
|
||||||
case DenaliID:
|
case DenaliID:
|
||||||
return &DenaliConfig
|
return &DenaliConfig
|
||||||
case CascadeID:
|
case CascadeID:
|
||||||
|
|
|
@ -23,8 +23,11 @@ func TestNetworkName(t *testing.T) {
|
||||||
if name := NetworkName(DenaliID); name != DenaliName {
|
if name := NetworkName(DenaliID); name != DenaliName {
|
||||||
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, DenaliName)
|
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, DenaliName)
|
||||||
}
|
}
|
||||||
if name := NetworkName(TestnetID); name != DenaliName {
|
if name := NetworkName(EverestID); name != EverestName {
|
||||||
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, DenaliName)
|
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, EverestName)
|
||||||
|
}
|
||||||
|
if name := NetworkName(TestnetID); name != EverestName {
|
||||||
|
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, EverestName)
|
||||||
}
|
}
|
||||||
if name := NetworkName(4294967295); name != "network-4294967295" {
|
if name := NetworkName(4294967295); name != "network-4294967295" {
|
||||||
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, "network-4294967295")
|
t.Fatalf("NetworkID was incorrectly named. Result: %s ; Expected: %s", name, "network-4294967295")
|
||||||
|
|
|
@ -16,13 +16,15 @@ var (
|
||||||
MainnetID uint32 = 1
|
MainnetID uint32 = 1
|
||||||
CascadeID uint32 = 2
|
CascadeID uint32 = 2
|
||||||
DenaliID uint32 = 3
|
DenaliID uint32 = 3
|
||||||
|
EverestID uint32 = 4
|
||||||
|
|
||||||
TestnetID uint32 = 3
|
TestnetID uint32 = 4
|
||||||
LocalID uint32 = 12345
|
LocalID uint32 = 12345
|
||||||
|
|
||||||
MainnetName = "mainnet"
|
MainnetName = "mainnet"
|
||||||
CascadeName = "cascade"
|
CascadeName = "cascade"
|
||||||
DenaliName = "denali"
|
DenaliName = "denali"
|
||||||
|
EverestName = "everest"
|
||||||
|
|
||||||
TestnetName = "testnet"
|
TestnetName = "testnet"
|
||||||
LocalName = "local"
|
LocalName = "local"
|
||||||
|
@ -31,6 +33,7 @@ var (
|
||||||
MainnetID: MainnetName,
|
MainnetID: MainnetName,
|
||||||
CascadeID: CascadeName,
|
CascadeID: CascadeName,
|
||||||
DenaliID: DenaliName,
|
DenaliID: DenaliName,
|
||||||
|
EverestID: EverestName,
|
||||||
|
|
||||||
LocalID: LocalName,
|
LocalID: LocalName,
|
||||||
}
|
}
|
||||||
|
@ -38,6 +41,7 @@ var (
|
||||||
MainnetName: MainnetID,
|
MainnetName: MainnetID,
|
||||||
CascadeName: CascadeID,
|
CascadeName: CascadeID,
|
||||||
DenaliName: DenaliID,
|
DenaliName: DenaliID,
|
||||||
|
EverestName: EverestID,
|
||||||
|
|
||||||
TestnetName: TestnetID,
|
TestnetName: TestnetID,
|
||||||
LocalName: LocalID,
|
LocalName: LocalID,
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
dbVersion = "v0.5.0"
|
dbVersion = "v0.6.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Results of parsing the CLI
|
// Results of parsing the CLI
|
||||||
|
|
|
@ -33,6 +33,12 @@ func (m Builder) PeerList(ipDescs []utils.IPDesc) (Msg, error) {
|
||||||
return m.Pack(PeerList, map[Field]interface{}{Peers: ipDescs})
|
return m.Pack(PeerList, map[Field]interface{}{Peers: ipDescs})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ping message
|
||||||
|
func (m Builder) Ping() (Msg, error) { return m.Pack(Ping, nil) }
|
||||||
|
|
||||||
|
// Pong message
|
||||||
|
func (m Builder) Pong() (Msg, error) { return m.Pack(Pong, nil) }
|
||||||
|
|
||||||
// GetAcceptedFrontier message
|
// GetAcceptedFrontier message
|
||||||
func (m Builder) GetAcceptedFrontier(chainID ids.ID, requestID uint32) (Msg, error) {
|
func (m Builder) GetAcceptedFrontier(chainID ids.ID, requestID uint32) (Msg, error) {
|
||||||
return m.Pack(GetAcceptedFrontier, map[Field]interface{}{
|
return m.Pack(GetAcceptedFrontier, map[Field]interface{}{
|
||||||
|
|
|
@ -132,6 +132,10 @@ func (op Op) String() string {
|
||||||
return "get_peerlist"
|
return "get_peerlist"
|
||||||
case PeerList:
|
case PeerList:
|
||||||
return "peerlist"
|
return "peerlist"
|
||||||
|
case Ping:
|
||||||
|
return "ping"
|
||||||
|
case Pong:
|
||||||
|
return "pong"
|
||||||
case GetAcceptedFrontier:
|
case GetAcceptedFrontier:
|
||||||
return "get_accepted_frontier"
|
return "get_accepted_frontier"
|
||||||
case AcceptedFrontier:
|
case AcceptedFrontier:
|
||||||
|
@ -166,22 +170,21 @@ const (
|
||||||
Version
|
Version
|
||||||
GetPeerList
|
GetPeerList
|
||||||
PeerList
|
PeerList
|
||||||
|
Ping
|
||||||
|
Pong
|
||||||
// Bootstrapping:
|
// Bootstrapping:
|
||||||
GetAcceptedFrontier
|
GetAcceptedFrontier
|
||||||
AcceptedFrontier
|
AcceptedFrontier
|
||||||
GetAccepted
|
GetAccepted
|
||||||
Accepted
|
Accepted
|
||||||
|
GetAncestors
|
||||||
|
MultiPut
|
||||||
// Consensus:
|
// Consensus:
|
||||||
Get
|
Get
|
||||||
Put
|
Put
|
||||||
PushQuery
|
PushQuery
|
||||||
PullQuery
|
PullQuery
|
||||||
Chits
|
Chits
|
||||||
// Bootstrapping:
|
|
||||||
// TODO: Move GetAncestors and MultiPut with the rest of the bootstrapping
|
|
||||||
// commands when we do non-backwards compatible upgrade
|
|
||||||
GetAncestors
|
|
||||||
MultiPut
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Defines the messages that can be sent/received with this network
|
// Defines the messages that can be sent/received with this network
|
||||||
|
@ -192,6 +195,8 @@ var (
|
||||||
Version: {NetworkID, NodeID, MyTime, IP, VersionStr},
|
Version: {NetworkID, NodeID, MyTime, IP, VersionStr},
|
||||||
GetPeerList: {},
|
GetPeerList: {},
|
||||||
PeerList: {Peers},
|
PeerList: {Peers},
|
||||||
|
Ping: {},
|
||||||
|
Pong: {},
|
||||||
// Bootstrapping:
|
// Bootstrapping:
|
||||||
GetAcceptedFrontier: {ChainID, RequestID},
|
GetAcceptedFrontier: {ChainID, RequestID},
|
||||||
AcceptedFrontier: {ChainID, RequestID, ContainerIDs},
|
AcceptedFrontier: {ChainID, RequestID, ContainerIDs},
|
||||||
|
|
|
@ -54,6 +54,7 @@ type metrics struct {
|
||||||
|
|
||||||
getVersion, version,
|
getVersion, version,
|
||||||
getPeerlist, peerlist,
|
getPeerlist, peerlist,
|
||||||
|
ping, pong,
|
||||||
getAcceptedFrontier, acceptedFrontier,
|
getAcceptedFrontier, acceptedFrontier,
|
||||||
getAccepted, accepted,
|
getAccepted, accepted,
|
||||||
get, getAncestors, put, multiPut,
|
get, getAncestors, put, multiPut,
|
||||||
|
@ -78,6 +79,8 @@ func (m *metrics) initialize(registerer prometheus.Registerer) error {
|
||||||
errs.Add(m.version.initialize(Version, registerer))
|
errs.Add(m.version.initialize(Version, registerer))
|
||||||
errs.Add(m.getPeerlist.initialize(GetPeerList, registerer))
|
errs.Add(m.getPeerlist.initialize(GetPeerList, registerer))
|
||||||
errs.Add(m.peerlist.initialize(PeerList, registerer))
|
errs.Add(m.peerlist.initialize(PeerList, registerer))
|
||||||
|
errs.Add(m.ping.initialize(Ping, registerer))
|
||||||
|
errs.Add(m.pong.initialize(Pong, registerer))
|
||||||
errs.Add(m.getAcceptedFrontier.initialize(GetAcceptedFrontier, registerer))
|
errs.Add(m.getAcceptedFrontier.initialize(GetAcceptedFrontier, registerer))
|
||||||
errs.Add(m.acceptedFrontier.initialize(AcceptedFrontier, registerer))
|
errs.Add(m.acceptedFrontier.initialize(AcceptedFrontier, registerer))
|
||||||
errs.Add(m.getAccepted.initialize(GetAccepted, registerer))
|
errs.Add(m.getAccepted.initialize(GetAccepted, registerer))
|
||||||
|
@ -103,6 +106,10 @@ func (m *metrics) message(msgType Op) *messageMetrics {
|
||||||
return &m.getPeerlist
|
return &m.getPeerlist
|
||||||
case PeerList:
|
case PeerList:
|
||||||
return &m.peerlist
|
return &m.peerlist
|
||||||
|
case Ping:
|
||||||
|
return &m.ping
|
||||||
|
case Pong:
|
||||||
|
return &m.pong
|
||||||
case GetAcceptedFrontier:
|
case GetAcceptedFrontier:
|
||||||
return &m.getAcceptedFrontier
|
return &m.getAcceptedFrontier
|
||||||
case AcceptedFrontier:
|
case AcceptedFrontier:
|
||||||
|
|
|
@ -43,6 +43,8 @@ const (
|
||||||
defaultGetVersionTimeout = 2 * time.Second
|
defaultGetVersionTimeout = 2 * time.Second
|
||||||
defaultAllowPrivateIPs = true
|
defaultAllowPrivateIPs = true
|
||||||
defaultGossipSize = 50
|
defaultGossipSize = 50
|
||||||
|
defaultPingPongTimeout = time.Minute
|
||||||
|
defaultPingFrequency = 3 * defaultPingPongTimeout / 4
|
||||||
|
|
||||||
// Request ID used when sending a Put message to gossip an accepted container
|
// Request ID used when sending a Put message to gossip an accepted container
|
||||||
// (ie not sent in response to a Get)
|
// (ie not sent in response to a Get)
|
||||||
|
@ -123,6 +125,8 @@ type network struct {
|
||||||
getVersionTimeout time.Duration
|
getVersionTimeout time.Duration
|
||||||
allowPrivateIPs bool
|
allowPrivateIPs bool
|
||||||
gossipSize int
|
gossipSize int
|
||||||
|
pingPongTimeout time.Duration
|
||||||
|
pingFrequency time.Duration
|
||||||
|
|
||||||
executor timer.Executor
|
executor timer.Executor
|
||||||
|
|
||||||
|
@ -184,6 +188,8 @@ func NewDefaultNetwork(
|
||||||
defaultGetVersionTimeout,
|
defaultGetVersionTimeout,
|
||||||
defaultAllowPrivateIPs,
|
defaultAllowPrivateIPs,
|
||||||
defaultGossipSize,
|
defaultGossipSize,
|
||||||
|
defaultPingPongTimeout,
|
||||||
|
defaultPingFrequency,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +221,8 @@ func NewNetwork(
|
||||||
getVersionTimeout time.Duration,
|
getVersionTimeout time.Duration,
|
||||||
allowPrivateIPs bool,
|
allowPrivateIPs bool,
|
||||||
gossipSize int,
|
gossipSize int,
|
||||||
|
pingPongTimeout time.Duration,
|
||||||
|
pingFrequency time.Duration,
|
||||||
) Network {
|
) Network {
|
||||||
net := &network{
|
net := &network{
|
||||||
log: log,
|
log: log,
|
||||||
|
@ -243,6 +251,8 @@ func NewNetwork(
|
||||||
getVersionTimeout: getVersionTimeout,
|
getVersionTimeout: getVersionTimeout,
|
||||||
allowPrivateIPs: allowPrivateIPs,
|
allowPrivateIPs: allowPrivateIPs,
|
||||||
gossipSize: gossipSize,
|
gossipSize: gossipSize,
|
||||||
|
pingPongTimeout: pingPongTimeout,
|
||||||
|
pingFrequency: pingFrequency,
|
||||||
|
|
||||||
disconnectedIPs: make(map[string]struct{}),
|
disconnectedIPs: make(map[string]struct{}),
|
||||||
connectedIPs: make(map[string]struct{}),
|
connectedIPs: make(map[string]struct{}),
|
||||||
|
|
|
@ -64,6 +64,24 @@ func (p *peer) Start() {
|
||||||
// Initially send the version to the peer
|
// Initially send the version to the peer
|
||||||
go p.Version()
|
go p.Version()
|
||||||
go p.requestVersion()
|
go p.requestVersion()
|
||||||
|
go p.sendPings()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *peer) sendPings() {
|
||||||
|
t := time.NewTicker(p.net.pingFrequency)
|
||||||
|
defer t.Stop()
|
||||||
|
|
||||||
|
for range t.C {
|
||||||
|
p.net.stateLock.Lock()
|
||||||
|
closed := p.closed
|
||||||
|
p.net.stateLock.Unlock()
|
||||||
|
|
||||||
|
if closed {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Ping()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// request the version from the peer until we get the version from them
|
// request the version from the peer until we get the version from them
|
||||||
|
@ -80,6 +98,7 @@ func (p *peer) requestVersion() {
|
||||||
if connected || closed {
|
if connected || closed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.GetVersion()
|
p.GetVersion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +107,11 @@ func (p *peer) requestVersion() {
|
||||||
func (p *peer) ReadMessages() {
|
func (p *peer) ReadMessages() {
|
||||||
defer p.Close()
|
defer p.Close()
|
||||||
|
|
||||||
|
if err := p.conn.SetReadDeadline(p.net.clock.Time().Add(p.net.pingPongTimeout)); err != nil {
|
||||||
|
p.net.log.Verbo("error on setting the connection read timeout %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
pendingBuffer := wrappers.Packer{}
|
pendingBuffer := wrappers.Packer{}
|
||||||
readBuffer := make([]byte, 1<<10)
|
readBuffer := make([]byte, 1<<10)
|
||||||
for {
|
for {
|
||||||
|
@ -218,7 +242,15 @@ func (p *peer) send(msg Msg) bool {
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
func (p *peer) handle(msg Msg) {
|
func (p *peer) handle(msg Msg) {
|
||||||
p.net.heartbeat()
|
p.net.heartbeat()
|
||||||
atomic.StoreInt64(&p.lastReceived, p.net.clock.Time().Unix())
|
|
||||||
|
currentTime := p.net.clock.Time()
|
||||||
|
atomic.StoreInt64(&p.lastReceived, currentTime.Unix())
|
||||||
|
|
||||||
|
if err := p.conn.SetReadDeadline(currentTime.Add(p.net.pingPongTimeout)); err != nil {
|
||||||
|
p.net.log.Verbo("error on setting the connection read timeout %s, closing the connection", err)
|
||||||
|
p.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
op := msg.Op()
|
op := msg.Op()
|
||||||
msgMetrics := p.net.message(op)
|
msgMetrics := p.net.message(op)
|
||||||
|
@ -235,6 +267,12 @@ func (p *peer) handle(msg Msg) {
|
||||||
case GetVersion:
|
case GetVersion:
|
||||||
p.getVersion(msg)
|
p.getVersion(msg)
|
||||||
return
|
return
|
||||||
|
case Ping:
|
||||||
|
p.ping(msg)
|
||||||
|
return
|
||||||
|
case Pong:
|
||||||
|
p.pong(msg)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !p.connected {
|
if !p.connected {
|
||||||
p.net.log.Debug("dropping message from %s because the connection hasn't been established yet", p.id)
|
p.net.log.Debug("dropping message from %s because the connection hasn't been established yet", p.id)
|
||||||
|
@ -318,6 +356,12 @@ func (p *peer) GetPeerList() {
|
||||||
p.Send(msg)
|
p.Send(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assumes the stateLock is not held
|
||||||
|
func (p *peer) SendPeerList() {
|
||||||
|
ips := p.net.validatorIPs()
|
||||||
|
p.PeerList(ips)
|
||||||
|
}
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
func (p *peer) PeerList(peers []utils.IPDesc) {
|
func (p *peer) PeerList(peers []utils.IPDesc) {
|
||||||
msg, err := p.net.b.PeerList(peers)
|
msg, err := p.net.b.PeerList(peers)
|
||||||
|
@ -326,7 +370,28 @@ func (p *peer) PeerList(peers []utils.IPDesc) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.Send(msg)
|
p.Send(msg)
|
||||||
return
|
}
|
||||||
|
|
||||||
|
// assumes the stateLock is not held
|
||||||
|
func (p *peer) Ping() {
|
||||||
|
msg, err := p.net.b.Ping()
|
||||||
|
p.net.log.AssertNoError(err)
|
||||||
|
if p.Send(msg) {
|
||||||
|
p.net.ping.numSent.Inc()
|
||||||
|
} else {
|
||||||
|
p.net.ping.numFailed.Inc()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// assumes the stateLock is not held
|
||||||
|
func (p *peer) Pong() {
|
||||||
|
msg, err := p.net.b.Pong()
|
||||||
|
p.net.log.AssertNoError(err)
|
||||||
|
if p.Send(msg) {
|
||||||
|
p.net.pong.numSent.Inc()
|
||||||
|
} else {
|
||||||
|
p.net.pong.numFailed.Inc()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
|
@ -458,17 +523,6 @@ func (p *peer) version(msg Msg) {
|
||||||
p.net.connected(p)
|
p.net.connected(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
|
||||||
func (p *peer) SendPeerList() {
|
|
||||||
ips := p.net.validatorIPs()
|
|
||||||
reply, err := p.net.b.PeerList(ips)
|
|
||||||
if err != nil {
|
|
||||||
p.net.log.Warn("failed to send PeerList message due to %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.Send(reply)
|
|
||||||
}
|
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
func (p *peer) getPeerList(_ Msg) { p.SendPeerList() }
|
func (p *peer) getPeerList(_ Msg) { p.SendPeerList() }
|
||||||
|
|
||||||
|
@ -488,6 +542,12 @@ func (p *peer) peerList(msg Msg) {
|
||||||
p.net.stateLock.Unlock()
|
p.net.stateLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assumes the stateLock is not held
|
||||||
|
func (p *peer) ping(_ Msg) { p.Pong() }
|
||||||
|
|
||||||
|
// assumes the stateLock is not held
|
||||||
|
func (p *peer) pong(_ Msg) {}
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
func (p *peer) getAcceptedFrontier(msg Msg) {
|
func (p *peer) getAcceptedFrontier(msg Msg) {
|
||||||
chainID, err := ids.ToID(msg.Get(ChainID).([]byte))
|
chainID, err := ids.ToID(msg.Get(ChainID).([]byte))
|
||||||
|
|
|
@ -56,7 +56,7 @@ var (
|
||||||
genesisHashKey = []byte("genesisID")
|
genesisHashKey = []byte("genesisID")
|
||||||
|
|
||||||
// Version is the version of this code
|
// Version is the version of this code
|
||||||
Version = version.NewDefaultVersion("avalanche", 0, 5, 5)
|
Version = version.NewDefaultVersion("avalanche", 0, 6, 0)
|
||||||
versionParser = version.NewDefaultParser()
|
versionParser = version.NewDefaultParser()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue