github.com/aergoio/aergo@v1.3.1/p2p/p2pcommon/consts.go (about)

     1  /*
     2   * @file
     3   * @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package p2pcommon
     7  
     8  import (
     9  	"fmt"
    10  	core "github.com/libp2p/go-libp2p-core"
    11  	"time"
    12  )
    13  
    14  // constants of p2p protocol since v0.3
    15  const (
    16  	// this magic number is useful only in handshaking
    17  	MAGICMain uint32 = 0x47416841
    18  	MAGICTest uint32 = 0x2e415429
    19  
    20  	MAGICRaftSnap uint32 = 0x8fae0fd4
    21  
    22  	SigLength = 16
    23  
    24  	MaxPayloadLength = 1 << 23 // 8MB
    25  
    26  	MaxBlockHeaderResponseCount = 10000
    27  	MaxBlockResponseCount       = 2000
    28  )
    29  
    30  // P2PVersion is version of p2p wire protocol. This version affects p2p handshake, data format transferred, etc
    31  type P2PVersion uint32
    32  
    33  func (v P2PVersion) Uint32() uint32 {
    34  	return uint32(v)
    35  }
    36  
    37  func (v P2PVersion) String() string {
    38  	return fmt.Sprintf("%d.%d.%d", (v&0x7fff0000)>>16, (v&0x0000ff00)>>8, v&0x000000ff)
    39  }
    40  
    41  const (
    42  	P2PVersionUnknown P2PVersion = 0x00000000
    43  	P2PVersion030     P2PVersion = 0x00000300
    44  	P2PVersion031     P2PVersion = 0x00000301 // pseudo version for supporting multi version
    45  	P2PVersion032     P2PVersion = 0x00000302 // added equal check of genesis block hash
    46  )
    47  
    48  // context of multiaddr, as higher type of p2p message
    49  const (
    50  	LegacyP2PSubAddr core.ProtocolID = "/aergop2p/0.3"
    51  	P2PSubAddr       core.ProtocolID = "/aergop2p"
    52  	RaftSnapSubAddr  core.ProtocolID = "/aergop2p/raftsnap"
    53  )
    54  
    55  // constants for handshake. for calculating byte offset of wire handshake
    56  const (
    57  	V030HSHeaderLength = 8
    58  	HSMagicLength      = 4
    59  	HSVersionLength    = 4
    60  	HSVerCntLength     = 4
    61  )
    62  const HSMaxVersionCnt = 16
    63  
    64  const HSError uint32 = 0
    65  
    66  // Codes in wire handshake
    67  type HSRespCode = uint32
    68  
    69  const (
    70  	_ uint32 = iota
    71  	HSCodeWrongHSReq
    72  	HSCodeNoMatchedVersion //
    73  	HSCodeAuthFail
    74  	HSCodeNoPermission
    75  	HSCodeInvalidState
    76  )
    77  
    78  // constants about private key
    79  const (
    80  	DefaultPkKeyPrefix = "aergo-peer"
    81  	DefaultPkKeyExt    = ".key"
    82  	DefaultPubKeyExt   = ".pub"
    83  	DefaultPeerIDExt   = ".id"
    84  )
    85  
    86  // constants for inter-communication of aergosvr
    87  const (
    88  	// other actor
    89  	DefaultActorMsgTTL = time.Second * 4
    90  )
    91  
    92  const (
    93  	// DesignatedNodeTTL is time to determine which the remote designated peer is not working.
    94  	DesignatedNodeTTL = time.Minute * 60
    95  
    96  	// DefaultNodeTTL is time to determine which the remote peer is not working.
    97  	DefaultNodeTTL = time.Minute * 10
    98  )