File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ import (
2424 "github.com/multiformats/go-multiaddr"
2525)
2626
27+ // Compile-time check to ensure Client implements P2PClient interface
28+ var _ P2PClient = (* Client )(nil )
29+
2730// Client represents a P2P messaging client.
2831type Client struct {
2932 config Config
@@ -43,7 +46,7 @@ type Client struct {
4346
4447// NewClient creates and initializes a new P2P client.
4548// It automatically starts the client and begins peer discovery.
46- func NewClient (config Config ) (* Client , error ) {
49+ func NewClient (config Config ) (P2PClient , error ) {
4750 if config .Name == "" {
4851 return nil , fmt .Errorf ("config.Name is required" )
4952 }
Original file line number Diff line number Diff line change 11package p2p
22
33import (
4+ "context"
45 "sync"
56 "time"
67
78 "github.com/libp2p/go-libp2p/core/peer"
89)
910
11+ // P2PClient defines the interface for a P2P messaging client.
12+ type P2PClient interface {
13+ // Subscribe subscribes to a topic and returns a channel that will receive messages.
14+ // The returned channel will be closed when the client is closed.
15+ Subscribe (topic string ) <- chan Message
16+
17+ // Publish publishes a message to the specified topic.
18+ Publish (ctx context.Context , topic string , data []byte ) error
19+
20+ // GetPeers returns information about all known peers on subscribed topics.
21+ GetPeers () []PeerInfo
22+
23+ // GetID returns this peer's ID as a string.
24+ GetID () string
25+
26+ // Close shuts down the client and releases all resources.
27+ Close () error
28+ }
29+
1030// Message represents a received message from a peer.
1131type Message struct {
1232 Topic string // The topic this message was received on
You can’t perform that action at this time.
0 commit comments