mirror of
https://github.com/vacp2p/universal-connectivity.git
synced 2026-01-10 07:38:15 -05:00
Removed JSON stuff, slowed down discover to be less spammy
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
|
||||
@@ -69,16 +68,7 @@ func JoinChatRoom(ctx context.Context, ps *pubsub.PubSub, selfID peer.ID, nickna
|
||||
|
||||
// Publish sends a message to the pubsub topic.
|
||||
func (cr *ChatRoom) Publish(message string) error {
|
||||
m := ChatMessage{
|
||||
Message: message,
|
||||
SenderID: cr.self.Pretty(),
|
||||
SenderNick: cr.nick,
|
||||
}
|
||||
msgBytes, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cr.topic.Publish(cr.ctx, msgBytes)
|
||||
return cr.topic.Publish(cr.ctx, []byte(message))
|
||||
}
|
||||
|
||||
func (cr *ChatRoom) ListPeers() []peer.ID {
|
||||
@@ -99,12 +89,9 @@ func (cr *ChatRoom) readLoop() {
|
||||
}
|
||||
cm := new(ChatMessage)
|
||||
cm.Message = string(msg.Data)
|
||||
cm.SenderID = string(msg.ID)
|
||||
cm.SenderNick = "unknown"
|
||||
cm.SenderID = msg.ID
|
||||
cm.SenderNick = string(msg.ID[len(msg.ID)-8])
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// send valid messages onto the Messages channel
|
||||
cr.Messages <- cm
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func Discover(ctx context.Context, h host.Host, dht *dht.IpfsDHT, rendezvous str
|
||||
|
||||
discovery.Advertise(ctx, routingDiscovery, rendezvous)
|
||||
|
||||
ticker := time.NewTicker(time.Second * 1)
|
||||
ticker := time.NewTicker(time.Second * 10)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user