Skip to content

Commit

Permalink
fix(core): sync bootstrap nodes when wake up
Browse files Browse the repository at this point in the history
  • Loading branch information
lead8000 committed Jun 7, 2023
1 parent a243e07 commit 24e64c1
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions core/fullNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewFullNode(nodeIP string, nodePort, bootstrapPort int, storage interfaces.
// }
// }()

go fullNode.joinNetwork(bootstrapPort)
fullNode.joinNetwork(bootstrapPort)
if isBootstrapNode {
go fullNode.bootstrap(bootstrapPort)
}
Expand Down Expand Up @@ -400,44 +400,44 @@ func (fn *FullNode) joinNetwork(boostrapPort int) {
if err != nil {
log.Fatal(err)
}
// ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
// defer cancel()

ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
fmt.Println("In AcceptTCP")
tcpConn, err := lis.AcceptTCP()
if err != nil {
select {
case <-ctx.Done():
fmt.Println("timeout reached")
return
default:
fmt.Println(err)
}
log.Fatal(err)
}
connChannel := make(chan net.Conn)

kBucket, err := utils.DeserializeMessage(tcpConn)
if err != nil {
log.Fatal(err)
}
fmt.Println("In Deserialize Messages")
go func() {
tcpConn, _ := lis.AcceptTCP()
connChannel <- tcpConn
}()

for i := 0; i < len(*kBucket); i++ {
node := (*kBucket)[i]
select {
case <-time.After(5 * time.Second):
fmt.Println("timeout reached")
return
case tcpConn := <-connChannel:

recvNode, err := NewClientNode(node.IP, node.Port).Ping(fn.dht.Node)
kBucket, err := utils.DeserializeMessage(tcpConn)
if err != nil {
log.Fatal(err)
}
fmt.Println("In Deserialize Messages")

if recvNode.Equal(node) {
fn.dht.RoutingTable.AddNode(node)
} else {
log.Fatal(errors.New("bad ping"))
for i := 0; i < len(*kBucket); i++ {
node := (*kBucket)[i]

recvNode, err := NewClientNode(node.IP, node.Port).Ping(fn.dht.Node)
if err != nil {
log.Fatal(err)
}

if recvNode.Equal(node) {
fn.dht.RoutingTable.AddNode(node)
} else {
log.Fatal(errors.New("bad ping"))
}
}
fmt.Println("Finish join network")
}
fmt.Println("Finish join network")
}

func (fn *FullNode) StoreValue(key string, data *[]byte) (string, error) {
Expand Down

0 comments on commit 24e64c1

Please sign in to comment.