-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1020 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"fmt"
"time"
"encoding/hex"
"github.com/invin/kkchain/crypto/blake2b"
"github.com/invin/kkchain/crypto/ed25519"
"github.com/invin/kkchain/p2p"
"github.com/invin/kkchain/p2p/impl"
)
func main() {
port := flag.String("p", "9998", "")
sec := flag.Int("s", 120, "")
keypath := flag.String("k", "", "")
flag.Parse()
config := p2p.Config{
SignaturePolicy: ed25519.New(),
HashPolicy: blake2b.New(),
}
listen := "/ip4/127.0.0.1/tcp/" + *port
net := impl.NewNetwork(*keypath, listen, config)
seconds := time.Duration(*sec)
if *port != "9998" {
remoteKeyPath := "node1.key"
pri, _ := p2p.LoadNodeKeyFromFile(remoteKeyPath)
pub, _ := ed25519.New().PrivateToPublic(pri)
node := "/ip4/127.0.0.1/tcp/9998"
node = hex.EncodeToString(pub) + "@" + node
fmt.Printf("remote peer: %s\n", node)
net.BootstrapNodes = []string{node}
}
err := net.Start()
if err != nil {
fmt.Printf("failed to start server: %s\n", err)
}
time.Sleep(time.Second * seconds)
}