提交 19eb3513 作者: Brian Tiger Chow

refactor(routing) rename grandcentral to supernode

thanks @mappum

remove .go-ipfs
上级 09186366
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync" syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
core "github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
corehttp "github.com/jbenet/go-ipfs/core/corehttp" corehttp "github.com/jbenet/go-ipfs/core/corehttp"
"github.com/jbenet/go-ipfs/core/corerouting" corerouting "github.com/jbenet/go-ipfs/core/corerouting"
config "github.com/jbenet/go-ipfs/repo/config" config "github.com/jbenet/go-ipfs/repo/config"
fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo" fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
s3datastore "github.com/jbenet/go-ipfs/thirdparty/s3-datastore" s3datastore "github.com/jbenet/go-ipfs/thirdparty/s3-datastore"
...@@ -68,7 +68,7 @@ func run() error { ...@@ -68,7 +68,7 @@ func run() error {
node, err := core.NewIPFSNode(ctx, node, err := core.NewIPFSNode(ctx,
core.OnlineWithOptions( core.OnlineWithOptions(
repo, repo,
corerouting.GrandCentralServer(enhanced), corerouting.SupernodeServer(enhanced),
core.DefaultHostOption), core.DefaultHostOption),
) )
if err != nil { if err != nil {
......
...@@ -8,8 +8,8 @@ import ( ...@@ -8,8 +8,8 @@ import (
core "github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/p2p/peer" "github.com/jbenet/go-ipfs/p2p/peer"
routing "github.com/jbenet/go-ipfs/routing" routing "github.com/jbenet/go-ipfs/routing"
grandcentral "github.com/jbenet/go-ipfs/routing/grandcentral" supernode "github.com/jbenet/go-ipfs/routing/supernode"
gcproxy "github.com/jbenet/go-ipfs/routing/grandcentral/proxy" gcproxy "github.com/jbenet/go-ipfs/routing/supernode/proxy"
) )
// NB: DHT option is included in the core to avoid 1) because it's a sane // NB: DHT option is included in the core to avoid 1) because it's a sane
...@@ -17,16 +17,16 @@ import ( ...@@ -17,16 +17,16 @@ import (
// the core if it's going to be the default) // the core if it's going to be the default)
var ( var (
errHostMissing = errors.New("grandcentral client requires a Host component") errHostMissing = errors.New("supernode routing client requires a Host component")
errIdentityMissing = errors.New("grandcentral server requires a peer ID identity") errIdentityMissing = errors.New("supernode routing server requires a peer ID identity")
errPeerstoreMissing = errors.New("grandcentral server requires a peerstore") errPeerstoreMissing = errors.New("supernode routing server requires a peerstore")
errServersMissing = errors.New("grandcentral client requires at least 1 server peer") errServersMissing = errors.New("supernode routing client requires at least 1 server peer")
) )
// GrandCentralServer returns a configuration for a routing server that stores // SupernodeServer returns a configuration for a routing server that stores
// routing records to the provided datastore. Only routing records are store in // routing records to the provided datastore. Only routing records are store in
// the datastore. // the datastore.
func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.RoutingOption { func SupernodeServer(recordSource datastore.ThreadSafeDatastore) core.RoutingOption {
return func(ctx context.Context, node *core.IpfsNode) (routing.IpfsRouting, error) { return func(ctx context.Context, node *core.IpfsNode) (routing.IpfsRouting, error) {
if node.Peerstore == nil { if node.Peerstore == nil {
return nil, errPeerstoreMissing return nil, errPeerstoreMissing
...@@ -37,7 +37,7 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing ...@@ -37,7 +37,7 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing
if node.Identity == "" { if node.Identity == "" {
return nil, errIdentityMissing return nil, errIdentityMissing
} }
server, err := grandcentral.NewServer(recordSource, node.Peerstore, node.Identity) server, err := supernode.NewServer(recordSource, node.Peerstore, node.Identity)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -45,13 +45,13 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing ...@@ -45,13 +45,13 @@ func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.Routing
Handler: server, Handler: server,
Local: node.Identity, Local: node.Identity,
} }
node.PeerHost.SetStreamHandler(gcproxy.ProtocolGCR, proxy.HandleStream) node.PeerHost.SetStreamHandler(gcproxy.ProtocolSNR, proxy.HandleStream)
return grandcentral.NewClient(proxy, node.PeerHost, node.Peerstore, node.Identity) return supernode.NewClient(proxy, node.PeerHost, node.Peerstore, node.Identity)
} }
} }
// TODO doc // TODO doc
func GrandCentralClient(remotes ...peer.PeerInfo) core.RoutingOption { func SupernodeClient(remotes ...peer.PeerInfo) core.RoutingOption {
return func(ctx context.Context, node *core.IpfsNode) (routing.IpfsRouting, error) { return func(ctx context.Context, node *core.IpfsNode) (routing.IpfsRouting, error) {
if len(remotes) < 1 { if len(remotes) < 1 {
return nil, errServersMissing return nil, errServersMissing
...@@ -78,7 +78,7 @@ func GrandCentralClient(remotes ...peer.PeerInfo) core.RoutingOption { ...@@ -78,7 +78,7 @@ func GrandCentralClient(remotes ...peer.PeerInfo) core.RoutingOption {
ids = append(ids, info.ID) ids = append(ids, info.ID)
} }
proxy := gcproxy.Standard(node.PeerHost, ids) proxy := gcproxy.Standard(node.PeerHost, ids)
node.PeerHost.SetStreamHandler(gcproxy.ProtocolGCR, proxy.HandleStream) node.PeerHost.SetStreamHandler(gcproxy.ProtocolSNR, proxy.HandleStream)
return grandcentral.NewClient(proxy, node.PeerHost, node.Peerstore, node.Identity) return supernode.NewClient(proxy, node.PeerHost, node.Peerstore, node.Identity)
} }
} }
package grandcentral package supernode
import ( import (
"bytes" "bytes"
...@@ -10,13 +10,13 @@ import ( ...@@ -10,13 +10,13 @@ import (
peer "github.com/jbenet/go-ipfs/p2p/peer" peer "github.com/jbenet/go-ipfs/p2p/peer"
routing "github.com/jbenet/go-ipfs/routing" routing "github.com/jbenet/go-ipfs/routing"
pb "github.com/jbenet/go-ipfs/routing/dht/pb" pb "github.com/jbenet/go-ipfs/routing/dht/pb"
proxy "github.com/jbenet/go-ipfs/routing/grandcentral/proxy" proxy "github.com/jbenet/go-ipfs/routing/supernode/proxy"
eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog" eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
errors "github.com/jbenet/go-ipfs/util/debugerror" errors "github.com/jbenet/go-ipfs/util/debugerror"
) )
var log = eventlog.Logger("grandcentral") var log = eventlog.Logger("supernode")
type Client struct { type Client struct {
peerhost host.Host peerhost host.Host
...@@ -128,7 +128,7 @@ func makeRecord(ps peer.Peerstore, p peer.ID, k u.Key, v []byte) (*pb.Record, er ...@@ -128,7 +128,7 @@ func makeRecord(ps peer.Peerstore, p peer.ID, k u.Key, v []byte) (*pb.Record, er
func (c *Client) Ping(ctx context.Context, id peer.ID) (time.Duration, error) { func (c *Client) Ping(ctx context.Context, id peer.ID) (time.Duration, error) {
defer log.EventBegin(ctx, "ping", id).Done() defer log.EventBegin(ctx, "ping", id).Done()
return time.Nanosecond, errors.New("grandcentral routing does not support the ping method") return time.Nanosecond, errors.New("supernode routing does not support the ping method")
} }
var _ routing.IpfsRouting = &Client{} var _ routing.IpfsRouting = &Client{}
...@@ -13,9 +13,9 @@ import ( ...@@ -13,9 +13,9 @@ import (
errors "github.com/jbenet/go-ipfs/util/debugerror" errors "github.com/jbenet/go-ipfs/util/debugerror"
) )
const ProtocolGCR = "/ipfs/grandcentral" const ProtocolSNR = "/ipfs/supernoderouting"
var log = eventlog.Logger("grandcentral/proxy") var log = eventlog.Logger("supernode/proxy")
type Proxy interface { type Proxy interface {
HandleStream(inet.Stream) HandleStream(inet.Stream)
...@@ -34,7 +34,7 @@ func Standard(h host.Host, remotes []peer.ID) Proxy { ...@@ -34,7 +34,7 @@ func Standard(h host.Host, remotes []peer.ID) Proxy {
func (p *standard) HandleStream(s inet.Stream) { func (p *standard) HandleStream(s inet.Stream) {
// TODO(brian): Should clients be able to satisfy requests? // TODO(brian): Should clients be able to satisfy requests?
log.Error("grandcentral client received (dropped) a routing message from", s.Conn().RemotePeer()) log.Error("supernode client received (dropped) a routing message from", s.Conn().RemotePeer())
s.Close() s.Close()
} }
...@@ -64,7 +64,7 @@ func (px *standard) sendMessage(ctx context.Context, m *dhtpb.Message, remote pe ...@@ -64,7 +64,7 @@ func (px *standard) sendMessage(ctx context.Context, m *dhtpb.Message, remote pe
if err = px.Host.Connect(ctx, peer.PeerInfo{ID: remote}); err != nil { if err = px.Host.Connect(ctx, peer.PeerInfo{ID: remote}); err != nil {
return err return err
} }
s, err := px.Host.NewStream(ProtocolGCR, remote) s, err := px.Host.NewStream(ProtocolSNR, remote)
if err != nil { if err != nil {
return err return err
} }
...@@ -100,7 +100,7 @@ func (px *standard) sendRequest(ctx context.Context, m *dhtpb.Message, remote pe ...@@ -100,7 +100,7 @@ func (px *standard) sendRequest(ctx context.Context, m *dhtpb.Message, remote pe
e.SetError(err) e.SetError(err)
return nil, err return nil, err
} }
s, err := px.Host.NewStream(ProtocolGCR, remote) s, err := px.Host.NewStream(ProtocolSNR, remote)
if err != nil { if err != nil {
e.SetError(err) e.SetError(err)
return nil, err return nil, err
......
package grandcentral package supernode
import ( import (
"fmt" "fmt"
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
datastore "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" datastore "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
peer "github.com/jbenet/go-ipfs/p2p/peer" peer "github.com/jbenet/go-ipfs/p2p/peer"
dhtpb "github.com/jbenet/go-ipfs/routing/dht/pb" dhtpb "github.com/jbenet/go-ipfs/routing/dht/pb"
proxy "github.com/jbenet/go-ipfs/routing/grandcentral/proxy" proxy "github.com/jbenet/go-ipfs/routing/supernode/proxy"
util "github.com/jbenet/go-ipfs/util" util "github.com/jbenet/go-ipfs/util"
errors "github.com/jbenet/go-ipfs/util/debugerror" errors "github.com/jbenet/go-ipfs/util/debugerror"
) )
...@@ -21,7 +21,7 @@ type Server struct { ...@@ -21,7 +21,7 @@ type Server struct {
*proxy.Loopback // so server can be injected into client *proxy.Loopback // so server can be injected into client
} }
// NewServer creates a new GrandCentral routing Server // NewServer creates a new Supernode routing Server
func NewServer(ds datastore.ThreadSafeDatastore, ps peer.Peerstore, local peer.ID) (*Server, error) { func NewServer(ds datastore.ThreadSafeDatastore, ps peer.Peerstore, local peer.ID) (*Server, error) {
s := &Server{local, ds, ps, nil} s := &Server{local, ds, ps, nil}
s.Loopback = &proxy.Loopback{ s.Loopback = &proxy.Loopback{
......
...@@ -21,9 +21,9 @@ import ( ...@@ -21,9 +21,9 @@ import (
testutil "github.com/jbenet/go-ipfs/util/testutil" testutil "github.com/jbenet/go-ipfs/util/testutil"
) )
func TestGrandcentralBootstrappedAddCat(t *testing.T) { func TestSupernodeBootstrappedAddCat(t *testing.T) {
// create 8 grandcentral bootstrap nodes // create 8 supernode-routing bootstrap nodes
// create 2 grandcentral clients both bootstrapped to the bootstrap nodes // create 2 supernode-routing clients both bootstrapped to the bootstrap nodes
// let the bootstrap nodes share a single datastore // let the bootstrap nodes share a single datastore
// add a large file on one node then cat the file from the other // add a large file on one node then cat the file from the other
conf := testutil.LatencyConfig{ conf := testutil.LatencyConfig{
...@@ -31,16 +31,16 @@ func TestGrandcentralBootstrappedAddCat(t *testing.T) { ...@@ -31,16 +31,16 @@ func TestGrandcentralBootstrappedAddCat(t *testing.T) {
RoutingLatency: 0, RoutingLatency: 0,
BlockstoreLatency: 0, BlockstoreLatency: 0,
} }
if err := RunGrandcentralBootstrappedAddCat(RandomBytes(100*unit.MB), conf); err != nil { if err := RunSupernodeBootstrappedAddCat(RandomBytes(100*unit.MB), conf); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func RunGrandcentralBootstrappedAddCat(data []byte, conf testutil.LatencyConfig) error { func RunSupernodeBootstrappedAddCat(data []byte, conf testutil.LatencyConfig) error {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
servers, clients, err := InitializeGrandCentralNetwork(ctx, 8, 2, conf) servers, clients, err := InitializeSupernodeNetwork(ctx, 8, 2, conf)
if err != nil { if err != nil {
return err return err
} }
...@@ -73,7 +73,7 @@ func RunGrandcentralBootstrappedAddCat(data []byte, conf testutil.LatencyConfig) ...@@ -73,7 +73,7 @@ func RunGrandcentralBootstrappedAddCat(data []byte, conf testutil.LatencyConfig)
return nil return nil
} }
func InitializeGrandCentralNetwork( func InitializeSupernodeNetwork(
ctx context.Context, ctx context.Context,
numServers, numClients int, numServers, numClients int,
conf testutil.LatencyConfig) ([]*core.IpfsNode, []*core.IpfsNode, error) { conf testutil.LatencyConfig) ([]*core.IpfsNode, []*core.IpfsNode, error) {
...@@ -100,7 +100,7 @@ func InitializeGrandCentralNetwork( ...@@ -100,7 +100,7 @@ func InitializeGrandCentralNetwork(
for i := range iter.N(numServers) { for i := range iter.N(numServers) {
p := serverPeers[i] p := serverPeers[i]
bootstrap, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf, bootstrap, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf,
corerouting.GrandCentralServer(routingDatastore))) corerouting.SupernodeServer(routingDatastore)))
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -117,7 +117,7 @@ func InitializeGrandCentralNetwork( ...@@ -117,7 +117,7 @@ func InitializeGrandCentralNetwork(
for i := range iter.N(numClients) { for i := range iter.N(numClients) {
p := clientPeers[i] p := clientPeers[i]
n, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf, n, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf,
corerouting.GrandCentralClient(bootstrapInfos...))) corerouting.SupernodeClient(bootstrapInfos...)))
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论