merge conflicts

pull/108/head
Richard Liu 6 years ago
commit c1bbe06e76
  1. 2
      crypto/cosi.go
  2. 7
      p2p/backoff.go
  3. 11
      p2p/helper.go
  4. 1
      p2pv2/host.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

@ -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
// BatchSizeInByte defines the size of buffer (64MB)
const BatchSizeInByte = 1 << 16
// ReadMessageContent 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{})
@ -62,12 +63,12 @@ func ReadMessageContent(conn net.Conn) ([]byte, error) {
bytesToRead := binary.BigEndian.Uint32(fourBytes)
//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, BatchSizeInByte)
ILOOP:
for {
timeoutDuration := 10 * time.Second
conn.SetReadDeadline(time.Now().Add(timeoutDuration))
if bytesToRead < BATCH_SIZE {
if bytesToRead < BatchSizeInByte {
// Read the last number of bytes less than 1024
tmpBuf = make([]byte, bytesToRead)
}
@ -91,6 +92,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{})
@ -104,6 +106,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)

@ -34,7 +34,6 @@ func InitHost(ip, port string) {
addr := fmt.Sprintf("/ip4/%s/tcp/%s", ip, port)
sourceAddr, err := multiaddr.NewMultiaddr(addr)
catchError(err)
// TODO(ricl): use ip as well.
priv := addrToPrivKey(addr)
myHost, err = libp2p.New(context.Background(),
libp2p.ListenAddrs(sourceAddr),

Loading…
Cancel
Save