diff --git a/beaconchain/beaconchain_handler.go b/beaconchain/beaconchain_handler.go index c3b7ba6c9..a7a2f0127 100644 --- a/beaconchain/beaconchain_handler.go +++ b/beaconchain/beaconchain_handler.go @@ -47,7 +47,7 @@ func (IDC *BeaconChain) BeaconChainHandler(conn net.Conn) { } switch msgCategory { case proto.Identity: - actionType := proto_identity.IdentityMessageType(msgType) + actionType := proto_identity.IDMessageType(msgType) switch actionType { case proto_identity.Identity: idMsgType, err := proto_identity.GetIdentityMessageType(msgPayload) diff --git a/crypto/cosi.go b/crypto/cosi.go index 675616053..4c98c2c69 100644 --- a/crypto/cosi.go +++ b/crypto/cosi.go @@ -1,5 +1,5 @@ /* -Package cosi implements the collective signing (CoSi) algorithm as presented in +Package crypto implements the collective signing (CoSi) algorithm as presented in the paper "Keeping Authorities 'Honest or Bust' with Decentralized Witness Cosigning" by Ewa Syta et al. See https://arxiv.org/abs/1503.08768. This package only provides the functionality for the cryptographic operations of diff --git a/p2p/backoff.go b/p2p/backoff.go index 2bac92e41..c57a636cb 100644 --- a/p2p/backoff.go +++ b/p2p/backoff.go @@ -16,6 +16,7 @@ type BackoffBase struct { Min, Cur, Max time.Duration } +// NewBackoffBase creates a new BackOffBase structure func NewBackoffBase(min, max time.Duration) *BackoffBase { return &BackoffBase{min, min, max} } @@ -40,21 +41,23 @@ func (b *BackoffBase) Sleep() { } } -// Adjust the duration. Subtypes shall implement this. +// Backoff adjusts the duration. Subtypes shall implement this. func (b *BackoffBase) Backoff() { // default implementation does not backoff } -// Exponential backoff. +// ExpBackoff is an exponential backoff data structure. type ExpBackoff struct { BackoffBase Factor float64 } +// NewExpBackoff creates a new ExpBackOff structure func NewExpBackoff(min, max time.Duration, factor float64) *ExpBackoff { return &ExpBackoff{*NewBackoffBase(min, max), factor} } +// Backoff implements the exponential backoff func (b *ExpBackoff) Backoff() { b.Cur = time.Duration(float64(b.Cur) * b.Factor) } diff --git a/p2p/helper.go b/p2p/helper.go index d748a0aae..b38c999d0 100644 --- a/p2p/helper.go +++ b/p2p/helper.go @@ -24,9 +24,10 @@ content (n bytes) - actual message content */ -const BATCH_SIZE = 1 << 16 +// BatchSize defines the size of buffer +const BatchSize = 1 << 16 -// Read the message type and content size, and return the actual content. +// ReadMessageContent reads the message type and content size, and return the actual content. func ReadMessageContent(conn net.Conn) ([]byte, error) { var ( contentBuf = bytes.NewBuffer([]byte{}) @@ -67,12 +68,12 @@ func ReadMessageContent(conn net.Conn) ([]byte, error) { //log.Printf("The content size is %d bytes.", bytesToRead) //// Read the content in chunk of 16 * 1024 bytes - tmpBuf := make([]byte, BATCH_SIZE) + tmpBuf := make([]byte, BatchSize) ILOOP: for { timeoutDuration := 10 * time.Second conn.SetReadDeadline(time.Now().Add(timeoutDuration)) - if bytesToRead < BATCH_SIZE { + if bytesToRead < BatchSize { // Read the last number of bytes less than 1024 tmpBuf = make([]byte, bytesToRead) } @@ -97,6 +98,7 @@ ILOOP: return contentBuf.Bytes(), nil } +// CreateMessage create a general message. FIXME: this is not used func CreateMessage(msgType byte, data []byte) []byte { buffer := bytes.NewBuffer([]byte{}) @@ -110,6 +112,7 @@ func CreateMessage(msgType byte, data []byte) []byte { return buffer.Bytes() } +// SendMessageContent send message over net connection. FIXME: this is not used func SendMessageContent(conn net.Conn, data []byte) { msgToSend := CreateMessage(byte(1), data) w := bufio.NewWriter(conn)