mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 19:37:46 +08:00
fix(gcr/s,c) register stream handlers
This commit is contained in:
parent
d80e9aba7a
commit
46bbd11e6b
@ -40,6 +40,7 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing
|
||||
Handler: server,
|
||||
Local: node.Identity,
|
||||
}
|
||||
node.PeerHost.SetStreamHandler(gcproxy.ProtocolGCR, proxy.HandleStream)
|
||||
return grandcentral.NewClient(proxy, node.Peerstore, node.Identity)
|
||||
}
|
||||
}
|
||||
@ -75,6 +76,7 @@ func GrandCentralClient(remotes ...peer.PeerInfo) core.RoutingOption {
|
||||
ids = append(ids, info.ID)
|
||||
}
|
||||
proxy := gcproxy.Standard(node.PeerHost, ids)
|
||||
node.PeerHost.SetStreamHandler(gcproxy.ProtocolGCR, proxy.HandleStream)
|
||||
return grandcentral.NewClient(proxy, node.Peerstore, node.Identity)
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ func (lb *Loopback) SendRequest(ctx context.Context, m *dhtpb.Message) (*dhtpb.M
|
||||
return lb.Handler.HandleRequest(ctx, lb.Local, m), nil
|
||||
}
|
||||
|
||||
func (lb *Loopback) handleNewStream(s inet.Stream) {
|
||||
func (lb *Loopback) HandleStream(s inet.Stream) {
|
||||
defer s.Close()
|
||||
pbr := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
|
||||
var incoming dhtpb.Message
|
||||
|
||||
@ -13,7 +13,10 @@ import (
|
||||
|
||||
var log = eventlog.Logger("proxy")
|
||||
|
||||
const ProtocolGCR = "/ipfs/grandcentral"
|
||||
|
||||
type Proxy interface {
|
||||
HandleStream(inet.Stream)
|
||||
SendMessage(ctx context.Context, m *dhtpb.Message) error
|
||||
SendRequest(ctx context.Context, m *dhtpb.Message) (*dhtpb.Message, error)
|
||||
}
|
||||
@ -27,7 +30,9 @@ func Standard(h host.Host, remotes []peer.ID) Proxy {
|
||||
return &standard{h, remotes}
|
||||
}
|
||||
|
||||
const ProtocolGCR = "/ipfs/grandcentral"
|
||||
func (p *standard) HandleStream(s inet.Stream) {
|
||||
panic("client received a GCR message")
|
||||
}
|
||||
|
||||
func (px *standard) SendMessage(ctx context.Context, m *dhtpb.Message) error {
|
||||
var err error
|
||||
|
||||
Loading…
Reference in New Issue
Block a user