Skip to content

Commit

Permalink
fix(net): fix joinNetwork and bootstrap to avoid that different subne…
Browse files Browse the repository at this point in the history
…ts collapse
  • Loading branch information
lead8000 committed Jun 11, 2023
1 parent 0c6ff53 commit 57c3505
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 89 deletions.
10 changes: 5 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ func main() {
defer cancel()
sender, err := client.Store(ctx)
if err != nil {
fmt.Println(err.Error())
//fmt.Println(err.Error())
}
keyHash := utils.GetSha1Hash(data)
dataBytes := []byte(data)
//fmt.Println("data bytes", dataBytes)
////fmt.Println("data bytes", dataBytes)
err = sender.Send(&pb.StoreData{Key: keyHash, Value: &pb.Data{Init: 0, End: int64(len(dataBytes)), Buffer: dataBytes}})
if err != nil {
fmt.Println(err.Error())
//fmt.Println(err.Error())
}
fmt.Println("Stored ID: ", keyHash, "Stored Data:", string(dataBytes))
//fmt.Println("Stored ID: ", keyHash, "Stored Data:", string(dataBytes))

case "ping":
if len(input) != 5 {
Expand Down Expand Up @@ -204,7 +204,7 @@ func main() {
idSender, _ := utils.NewID(bootIp, bootPort)
pbNode, err := client.Ping(ctx, &pb.Node{ID: idSender, IP: bootIp, Port: int32(bootPort)})
if err != nil {
fmt.Println(err)
//fmt.Println(err)
}
fmt.Println("Made Ping from ", bootIp, ":", bootPort, "to", pbNode.IP, ":", pbNode.Port)
nearestNodes, _ := fullNodeServer.LookUp(target)
Expand Down
13 changes: 6 additions & 7 deletions core/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"bytes"
"fmt"

"github.com/science-engineering-art/kademlia-grpc/interfaces"
"github.com/science-engineering-art/kademlia-grpc/structs"
Expand All @@ -15,14 +14,14 @@ type DHT struct {
}

func (fn *DHT) Store(key []byte, data *[]byte) error {
fmt.Printf("INIT DHT.Store(%v) len(*data)=%d\n", key, len(*data))
defer fmt.Printf("END DHT.Store(%v)\n", key)
//fmt.Printf("INIT DHT.Store(%v) len(*data)=%d\n", key, len(*data))
// defer //fmt.Printf("END DHT.Store(%v)\n", key)

fmt.Println("Before Storage.Create()")
//fmt.Println("Before Storage.Create()")
err := fn.Storage.Create(key, data)
fmt.Println("After Storage.Create()")
//fmt.Println("After Storage.Create()")
if err != nil {
fmt.Println("ERROR line:23 DHT.Storage.Create()")
//fmt.Println("ERROR line:23 DHT.Storage.Create()")
return err
}
return nil
Expand All @@ -31,7 +30,7 @@ func (fn *DHT) Store(key []byte, data *[]byte) error {
func (fn *DHT) FindValue(infoHash *[]byte, start int64, end int64) (value *[]byte, neighbors *[]structs.Node) {
value, err := fn.Storage.Read(*infoHash, start, end)
if err != nil {
//fmt.Println("Find Value error: ", err)
////fmt.Println("Find Value error: ", err)
neighbors = fn.RoutingTable.GetClosestContacts(structs.Alpha, *infoHash, []*structs.Node{&fn.Node}).Nodes
return nil, neighbors
}
Expand Down
Loading

0 comments on commit 57c3505

Please sign in to comment.