WIP experimenting with discovery
This commit is contained in:
@@ -16,11 +16,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
topicNameFlag = flag.String("topicName", "akdjlask-23klaj2idalj2-ajl2kjd3i-2ldakjd2", "name of topic to join")
|
||||
topicNameFlag = flag.String("topicName", "pentapass", "name of topic to join")
|
||||
dbPath = flag.String("db", "./db", "db file path")
|
||||
nameSpace = flag.String("namespace", "crdt", "namespace")
|
||||
logger = logging.Logger("globaldb")
|
||||
// topicName = "globaldb-example"
|
||||
// netTopic = "globaldb-example-net"
|
||||
// config = "globaldb-example"
|
||||
)
|
||||
@@ -58,7 +57,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//topic, err := ps.Join(*topicNameFlag)
|
||||
//_, err = ps.Join(*topicNameFlag)
|
||||
//if err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" d2Version="v0.6.5" preserveAspectRatio="xMinYMin meet" viewBox="0 0 1984 3328"><svg id="d2-svg" class="d2-1224808988" width="1984" height="3328" viewBox="-91 -121 1984 3328"><rect x="-91.000000" y="-121.000000" width="1984.000000" height="3328.000000" rx="0.000000" class=" fill-N7" stroke-width="0" /><style type="text/css"><![CDATA[
|
||||
<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" d2Version="v0.6.6" preserveAspectRatio="xMinYMin meet" viewBox="0 0 1984 3328"><svg id="d2-svg" class="d2-1224808988" width="1984" height="3328" viewBox="-91 -121 1984 3328"><rect x="-91.000000" y="-121.000000" width="1984.000000" height="3328.000000" rx="0.000000" class=" fill-N7" stroke-width="0" /><style type="text/css"><![CDATA[
|
||||
.d2-1224808988 .text {
|
||||
font-family: "d2-1224808988-font-regular";
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
@@ -20,8 +20,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p/core/control"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
//"github.com/libp2p/go-libp2p/core/peerstore"
|
||||
drouting "github.com/libp2p/go-libp2p/p2p/discovery/routing"
|
||||
dutil "github.com/libp2p/go-libp2p/p2p/discovery/util"
|
||||
discovery "github.com/libp2p/go-libp2p/p2p/discovery/routing"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
ipfslite "github.com/hsanjuan/ipfs-lite"
|
||||
"github.com/google/uuid"
|
||||
@@ -511,7 +510,7 @@ func PrintDBContent(ctx context.Context, store *badger.Datastore) {
|
||||
|
||||
func (s *StorageHandler) ListNamespaces() []string {
|
||||
var result []string
|
||||
for k, _ := range s.Namespaces {
|
||||
for k := range s.Namespaces {
|
||||
result = append(result, k)
|
||||
}
|
||||
|
||||
@@ -555,11 +554,12 @@ func CreateNamespace(ID string, storageHandler *StorageHandler) (*Namespace, err
|
||||
fmt.Printf("Creating Namespace %s\n", ID)
|
||||
err := storageHandler.PubSub.RegisterTopicValidator(
|
||||
ID, //== topicName
|
||||
func(ctx context.Context, _ peer.ID, msg *pubsub.Message) bool {
|
||||
func(ctx context.Context, id peer.ID, msg *pubsub.Message) bool {
|
||||
fmt.Printf("PubSubmsg TOPIC: %s, PEER: %s\n", ID, id)
|
||||
signer := msg.GetFrom()
|
||||
trusted := IsTrustedPeer(ctx, signer, ID, storageHandler.Config)
|
||||
if !trusted {
|
||||
logger.Debug("discarded pubsub message from non trusted source %s ", signer)
|
||||
fmt.Printf("discarded pubsub message from non trusted source %s\n", signer)
|
||||
}
|
||||
return trusted
|
||||
},
|
||||
@@ -634,8 +634,8 @@ func initDHT(ctx context.Context, h host.Host) *dht.IpfsDHT {
|
||||
}
|
||||
|
||||
func DiscoverPeers(ctx context.Context, h host.Host, dht *dht.IpfsDHT) {
|
||||
routingDiscovery := drouting.NewRoutingDiscovery(dht)
|
||||
dutil.Advertise(ctx, routingDiscovery, topicNameFlag)
|
||||
routingDiscovery := discovery.NewRoutingDiscovery(dht)
|
||||
routingDiscovery.Advertise(ctx, topicNameFlag)
|
||||
|
||||
// Look for others who have announced and attempt to connect to them
|
||||
anyConnected := false
|
||||
@@ -648,29 +648,21 @@ func DiscoverPeers(ctx context.Context, h host.Host, dht *dht.IpfsDHT) {
|
||||
panic(err)
|
||||
}
|
||||
for peer := range peerChan {
|
||||
if peer.ID == h.ID() {
|
||||
if peer.ID == h.ID() || len(peer.Addrs) == 0 {
|
||||
continue // No self connection
|
||||
}
|
||||
|
||||
|
||||
fmt.Printf("Trying to connect to a peer with id %s", peer.ID.String())
|
||||
if h.Network().Connectedness(peer.ID) != network.Connected {
|
||||
_, err = h.Network().DialPeer(ctx, peer.ID)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Connected to:", peer.ID)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Failed connecting to %s, error: %s\n", peer.ID, err)
|
||||
if h.Network().Connectedness(peer.ID) == network.Connected {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("Connecting to peer with id %s", peer.ID.String())
|
||||
err := h.Connect(ctx, peer)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed connecting to %s, error: %s\n", peer.ID, err)
|
||||
} else {
|
||||
fmt.Println("Connected to:", peer.ID)
|
||||
}
|
||||
//fmt.Printf("Trying to connect to a peer with id %s", peer.ID.String())
|
||||
//err := h.Connect(ctx, peer)
|
||||
//if err != nil {
|
||||
// fmt.Printf("Failed connecting to %s, error: %s\n", peer.ID, err)
|
||||
//} else {
|
||||
// fmt.Println("Connected to:", peer.ID)
|
||||
// anyConnected = true
|
||||
//}
|
||||
}
|
||||
}
|
||||
fmt.Println("Peer discovery complete")
|
||||
|
||||
Reference in New Issue
Block a user