-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Tiger Chow
committed
Jan 28, 2015
1 parent
bbcec1d
commit 8e8da82
Showing
3 changed files
with
109 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package corerouting | ||
|
||
import ( | ||
"errors" | ||
|
||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" | ||
datastore "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" | ||
core "github.com/jbenet/go-ipfs/core" | ||
"github.com/jbenet/go-ipfs/p2p/peer" | ||
routing "github.com/jbenet/go-ipfs/routing" | ||
grandcentral "github.com/jbenet/go-ipfs/routing/grandcentral" | ||
gcproxy "github.com/jbenet/go-ipfs/routing/grandcentral/proxy" | ||
) | ||
|
||
// NB: DHT option is included in the core to avoid 1) because it's a sane | ||
// default and 2) to avoid a circular dependency (it needs to be referenced in | ||
// the core if it's going to be the default) | ||
|
||
var ( | ||
errHostMissing = errors.New("grandcentral client requires a Host component") | ||
errIdentityMissing = errors.New("grandcentral server requires a peer ID identity") | ||
errPeerstoreMissing = errors.New("grandcentral server requires a peerstore") | ||
errServersMissing = errors.New("grandcentral client requires at least 1 server peer") | ||
) | ||
|
||
// TODO doc | ||
func GrandCentralServer(recordSource datastore.ThreadSafeDatastore) core.RoutingOption { | ||
return func(ctx context.Context, node *core.IpfsNode) (routing.IpfsRouting, error) { | ||
if node.Peerstore == nil { | ||
return nil, errPeerstoreMissing | ||
} | ||
if node.Identity == "" { | ||
return nil, errIdentityMissing | ||
} | ||
server, err := grandcentral.NewServer(recordSource, node.Peerstore, node.Identity) | ||
if err != nil { | ||
return nil, err | ||
} | ||
proxy := &gcproxy.Loopback{ | ||
Handler: server, | ||
Local: node.Identity, | ||
} | ||
return grandcentral.NewClient(proxy, node.Peerstore, node.Identity) | ||
} | ||
} | ||
|
||
// TODO doc | ||
func GrandCentralClient(remotes ...peer.PeerInfo) core.RoutingOption { | ||
return func(ctx context.Context, node *core.IpfsNode) (routing.IpfsRouting, error) { | ||
if len(remotes) < 1 { | ||
return nil, errServersMissing | ||
} | ||
if node.PeerHost == nil { | ||
return nil, errHostMissing | ||
} | ||
if node.Identity == "" { | ||
return nil, errIdentityMissing | ||
} | ||
|
||
// TODO right now, I think this has a hidden dependency on the | ||
// bootstrap peers provided to the core.Node. Careful... | ||
|
||
proxy := gcproxy.Standard(node.PeerHost, remotes[0].ID) // TODO support more than one | ||
return grandcentral.NewClient(proxy, node.Peerstore, node.Identity) | ||
} | ||
} |