Merge pull request #115 from harmony-one/HAR-84_golint_fixes

HAR-84: fix golint warnings in crytpo, p2p
pull/121/head
Leo Chen 6 years ago committed by GitHub
commit 545f29afa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      beaconchain/beaconchain_handler.go
  2. 2
      crypto/cosi.go
  3. 7
      p2p/backoff.go
  4. 11
      p2p/helper.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)

@ -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

@ -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)
}

@ -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)

Loading…
Cancel
Save