Skip to content

Commit

Permalink
fix interval, remove dht options
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 13, 2024
1 parent 4fdd512 commit 8d4b4ab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
56 changes: 43 additions & 13 deletions app/p2p-Node/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,7 @@ func CreateHost() host.Host {
// If you don't have any bootstrapPeers, you can use dht.DefaultBootstrapPeers
// or an empty list.
func NewDHT(ctx context.Context, host host.Host, bootstrapPeers []multiaddr.Multiaddr) (*dht.IpfsDHT, error) {
var options []dht.Option

// if no bootstrap peers, make this peer act as a bootstraping node
// other peers can use this peers ipfs address for peer discovery via dht
if len(bootstrapPeers) == 0 {
options = append(options, dht.Mode(dht.ModeServer))
}

// set our DiscoveryServiceTag as the protocol prefix so we can discover
// peers we're interested in.
options = append(options, dht.ProtocolPrefix("/"+DiscoveryServiceTag))

kdht, err := dht.New(ctx, host, options...)
kdht, err := dht.New(ctx, host)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -108,4 +96,46 @@ func Discover(ctx context.Context, h host.Host, dht *dht.IpfsDHT) {

// Advertise our addresses on rendezvous
discovery.Advertise(ctx, routingDiscovery, DiscoveryServiceTag)
// // Search for peers every DiscoveryInterval
// ticker := time.NewTicker(DiscoveryInterval)
// quit := make(chan struct{})
// fmt.Println("ok")

// go func() {
// for {
// select {
// case <-ticker.C:
// fmt.Println("ok")
// // Search for other peers advertising on rendezvous and
// // connect to them.
// peers, err := discovery.FindPeers(ctx, routingDiscovery, DiscoveryServiceTag)
// if err != nil {
// panic(err)
// }

// for _, p := range peers {
// if p.ID == h.ID() {
// fmt.Println("self")
// continue
// }
// fmt.Println("here")
// if h.Network().Connectedness(p.ID) != network.Connected {
// _, err = h.Network().DialPeer(ctx, p.ID)
// if err != nil {
// fmt.Printf("Failed to connect to peer (%s): %s", p.ID, err.Error())

// fmt.Println()
// continue
// }
// fmt.Println("Connected to peer", p.ID.String())
// }
// }
// case <-quit:
// ticker.Stop()
// return
// }

// }
// }()

}
2 changes: 1 addition & 1 deletion app/p2p-Node/p2p-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Init() {

go p2pHost.Discover(ctx, ha, dht)

ticker := time.NewTicker(1 * time.Second)
ticker := time.NewTicker(10 * time.Second)
quit := make(chan struct{})
go func() {
for {
Expand Down

0 comments on commit 8d4b4ab

Please sign in to comment.