diff --git a/core/corerouting/core.go b/core/corerouting/core.go index cb040bcd4..f3c92fcef 100644 --- a/core/corerouting/core.go +++ b/core/corerouting/core.go @@ -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) } } diff --git a/routing/grandcentral/proxy/loopback.go b/routing/grandcentral/proxy/loopback.go index ba598c3ea..e5fa39deb 100644 --- a/routing/grandcentral/proxy/loopback.go +++ b/routing/grandcentral/proxy/loopback.go @@ -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 diff --git a/routing/grandcentral/proxy/standard.go b/routing/grandcentral/proxy/standard.go index b3d1fc5d8..996f2f5e7 100644 --- a/routing/grandcentral/proxy/standard.go +++ b/routing/grandcentral/proxy/standard.go @@ -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