The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/p2pv2/util.go

31 lines
659 B

package p2pv2
import (
"bufio"
"hash/fnv"
"math/rand"
"github.com/harmony-one/harmony/log"
ic "github.com/libp2p/go-libp2p-crypto"
)
func catchError(err error) {
if err != nil {
log.Error("catchError", "err", err)
panic(err)
}
}
func addrToPrivKey(addr string) ic.PrivKey {
h := fnv.New32a()
_, err := h.Write([]byte(addr))
catchError(err)
r := rand.New(rand.NewSource(int64(h.Sum32()))) // Hack: forcing the random see to be the hash of addr so that we can recover priv from ip + port.
priv, _, err := ic.GenerateKeyPairWithReader(ic.RSA, 512, r)
return priv
}
func writeData(w *bufio.Writer, data []byte) {
w.Write(data)
w.Flush()
}