MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / initNodePeers

Function initNodePeers

cmd/cqld/initconf.go:28–97  ·  view source on GitHub ↗
(nodeID proto.NodeID, publicKeystorePath string)

Source from the content-addressed store, hash-verified

26)
27
28func initNodePeers(nodeID proto.NodeID, publicKeystorePath string) (nodes *[]proto.Node, peers *proto.Peers, thisNode *proto.Node, err error) {
29 privateKey, err := kms.GetLocalPrivateKey()
30 if err != nil {
31 log.WithError(err).Fatal("get local private key failed")
32 }
33
34 peers = &proto.Peers{
35 PeersHeader: proto.PeersHeader{
36 Term: 1,
37 Leader: conf.GConf.BP.NodeID,
38 },
39 }
40
41 if conf.GConf.KnownNodes != nil {
42 for i, n := range conf.GConf.KnownNodes {
43 if n.Role == proto.Leader || n.Role == proto.Follower {
44 //FIXME all KnownNodes
45 conf.GConf.KnownNodes[i].PublicKey = kms.BP.PublicKey
46 peers.Servers = append(peers.Servers, n.ID)
47 }
48 }
49 }
50
51 log.Debugf("AllNodes:\n %#v\n", conf.GConf.KnownNodes)
52
53 err = peers.Sign(privateKey)
54 if err != nil {
55 log.WithError(err).Error("sign peers failed")
56 return nil, nil, nil, err
57 }
58 log.Debugf("peers:\n %#v\n", peers)
59
60 //route.initResolver()
61 kms.InitPublicKeyStore(publicKeystorePath, nil)
62
63 // set p route and public keystore
64 if conf.GConf.KnownNodes != nil {
65 for i, p := range conf.GConf.KnownNodes {
66 rawNodeIDHash, err := hash.NewHashFromStr(string(p.ID))
67 if err != nil {
68 log.WithError(err).Error("load hash from node id failed")
69 return nil, nil, nil, err
70 }
71 log.WithFields(log.Fields{
72 "node": rawNodeIDHash.String(),
73 "addr": p.Addr,
74 }).Debug("set node addr")
75 rawNodeID := &proto.RawNodeID{Hash: *rawNodeIDHash}
76 route.SetNodeAddrCache(rawNodeID, p.Addr)
77 node := &proto.Node{
78 ID: p.ID,
79 Addr: p.Addr,
80 DirectAddr: p.DirectAddr,
81 PublicKey: p.PublicKey,
82 Nonce: p.Nonce,
83 Role: p.Role,
84 }
85 err = kms.SetNode(node)

Callers 2

runNodeFunction · 0.85

Calls 15

GetLocalPrivateKeyFunction · 0.92
WithErrorFunction · 0.92
DebugfFunction · 0.92
InitPublicKeyStoreFunction · 0.92
NewHashFromStrFunction · 0.92
WithFieldsFunction · 0.92
SetNodeAddrCacheFunction · 0.92
SetNodeFunction · 0.92
WithFieldFunction · 0.92
SetLocalNodeIDNonceFunction · 0.92
FatalMethod · 0.80
ErrorMethod · 0.80

Tested by 1