Skip to content

Commit

Permalink
Adds missing bootstrap.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Apr 1, 2024
1 parent 6688794 commit 40a7b6a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bootstrap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"encoding/json"
"fmt"
"io"
"net/http"
)

func Bootstrap() {
// Connect to all peers' peers
peers := GetPeers()
for _, peer := range peers {
// Get the peer's peers
req, err := http.NewRequest(http.MethodGet, peer+"/peers", nil)
if err != nil {
panic(err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Peer is down.")
continue
}
peerPeersBytes, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var peerPeers []string
err = json.Unmarshal(peerPeersBytes, &peerPeers)
for _, peerPeer := range peerPeers {
// Add the peer's peers to the list of peers
AddPeer(peerPeer)
}
}
}

0 comments on commit 40a7b6a

Please sign in to comment.