WIP experimenting with discovery

This commit is contained in:
2024-10-08 18:49:05 +02:00
parent 9fce13c6db
commit 705ea09692
2 changed files with 8 additions and 8 deletions

View File

@@ -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,10 +57,10 @@ func main() {
panic(err)
}
//topic, err := ps.Join(*topicNameFlag)
//if err != nil {
// panic(err)
//}
_, err = ps.Join(*topicNameFlag)
if err != nil {
panic(err)
}
go storage.DiscoverPeers(ctx, h, dht)

View File

@@ -555,7 +555,8 @@ 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 {
@@ -653,8 +654,8 @@ func DiscoverPeers(ctx context.Context, h host.Host, dht *dht.IpfsDHT) {
}
fmt.Printf("Trying to connect to a peer with id %s", peer.ID.String())
if h.Network().Connectedness(peer.ID) != network.Connected {
fmt.Printf("Trying to connect to a peer with id %s\n", peer.ID.String())
_, err = h.Network().DialPeer(ctx, peer.ID)
if err != nil {