Commit 9e5b3b77 authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(gcr/c) pass host.Host into GCR client

parent ea9ea794
......@@ -29,6 +29,9 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing
if node.Peerstore == nil {
return nil, errPeerstoreMissing
}
if node.PeerHost == nil {
return nil, errHostMissing
}
if node.Identity == "" {
return nil, errIdentityMissing
}
......@@ -41,7 +44,7 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing
Local: node.Identity,
}
node.PeerHost.SetStreamHandler(gcproxy.ProtocolGCR, proxy.HandleStream)
return grandcentral.NewClient(proxy, node.Peerstore, node.Identity)
return grandcentral.NewClient(proxy, node.PeerHost, node.Peerstore, node.Identity)
}
}
......@@ -77,6 +80,6 @@ func GrandCentralClient(remotes ...peer.PeerInfo) core.RoutingOption {
}
proxy := gcproxy.Standard(node.PeerHost, ids)
node.PeerHost.SetStreamHandler(gcproxy.ProtocolGCR, proxy.HandleStream)
return grandcentral.NewClient(proxy, node.Peerstore, node.Identity)
return grandcentral.NewClient(proxy, node.PeerHost, node.Peerstore, node.Identity)
}
}
......@@ -6,6 +6,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
"github.com/jbenet/go-ipfs/p2p/host"
peer "github.com/jbenet/go-ipfs/p2p/peer"
routing "github.com/jbenet/go-ipfs/routing"
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
......@@ -18,17 +19,19 @@ import (
var log = eventlog.Logger("grandcentral")
type Client struct {
peerhost host.Host
peerstore peer.Peerstore
proxy proxy.Proxy
local peer.ID
}
// TODO take in datastore/cache
func NewClient(px proxy.Proxy, ps peer.Peerstore, local peer.ID) (*Client, error) {
func NewClient(px proxy.Proxy, h host.Host, ps peer.Peerstore, local peer.ID) (*Client, error) {
return &Client{
proxy: px,
local: local,
peerstore: ps,
peerhost: h,
}, nil
}
......@@ -79,7 +82,8 @@ func (c *Client) Provide(ctx context.Context, k u.Key) error {
pri := []pb.PeerRoutingInfo{
pb.PeerRoutingInfo{
PeerInfo: peer.PeerInfo{
ID: c.local,
ID: c.local,
Addrs: c.peerhost.Addrs(),
},
},
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment