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.
34 lines
671 B
34 lines
671 B
6 years ago
|
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) {
|
||
|
for {
|
||
|
w.Write(data)
|
||
|
w.Flush()
|
||
|
}
|
||
|
}
|