mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 18:05:32 +08:00
catch ipns branch up to master and make all things compile
This commit is contained in:
@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
||||
|
@ -3,8 +3,9 @@ package main
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/gonuts/flag"
|
||||
"github.com/jbenet/commander"
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
||||
"github.com/jbenet/go-ipfs/core/commands"
|
||||
"github.com/jbenet/go-ipfs/daemon"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
@ -27,18 +28,22 @@ func pinCmd(c *commander.Command, inp []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
com := daemon.NewCommand()
|
||||
com.Command = "pin"
|
||||
com.Args = inp
|
||||
cmd := daemon.NewCommand()
|
||||
cmd.Command = "pin"
|
||||
cmd.Args = inp
|
||||
|
||||
err := daemon.SendCommand(com, "localhost:12345")
|
||||
err := daemon.SendCommand(cmd, "localhost:12345")
|
||||
if err != nil {
|
||||
n, err := localNode(false)
|
||||
conf, err := getConfigDir(c.Parent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := localNode(conf, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
daemon.ExecuteCommand(com, n, os.Stdout)
|
||||
return commands.Pin(n, cmd.Args, cmd.Opts, os.Stdout)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||
"github.com/jbenet/go-ipfs/daemon"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
@ -19,12 +22,26 @@ var cmdIpfsRun = &commander.Command{
|
||||
func runCmd(c *commander.Command, inp []string) error {
|
||||
u.Debug = true
|
||||
|
||||
n, err := localNode(true)
|
||||
conf, err := getConfigDir(c.Parent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := localNode(conf, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dl, err := daemon.NewDaemonListener(n, "localhost:12345")
|
||||
// launch the RPC endpoint.
|
||||
if n.Config.RPCAddress == "" {
|
||||
return errors.New("no config.RPCAddress endpoint supplied")
|
||||
}
|
||||
|
||||
maddr, err := ma.NewMultiaddr(n.Config.RPCAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dl, err := daemon.NewDaemonListener(n, maddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -229,8 +229,7 @@ func (s *SecurePipe) handleSecureIn(hashType string, tIV, tCKey, tMKey []byte) {
|
||||
for {
|
||||
data, ok := <-s.insecure.In
|
||||
if !ok {
|
||||
u.DOut("Closing incoming proxy.\n")
|
||||
close(s.In)
|
||||
close(s.Duplex.In)
|
||||
return
|
||||
}
|
||||
|
||||
@ -267,8 +266,6 @@ func (s *SecurePipe) handleSecureOut(hashType string, mIV, mCKey, mMKey []byte)
|
||||
for {
|
||||
data, ok := <-s.Out
|
||||
if !ok {
|
||||
u.DOut("Closing outgoing proxy.\n")
|
||||
close(s.Out)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,5 @@ func (s *SecurePipe) Close() error {
|
||||
|
||||
s.cancel()
|
||||
s.cancel = nil
|
||||
close(s.In)
|
||||
return nil
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ func Mount(ipfs *core.IpfsNode, fpath string) error {
|
||||
}
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
}
|
||||
ipfs.Swarm.Close()
|
||||
ipfs.Network.Close()
|
||||
}()
|
||||
|
||||
c, err := fuse.Mount(fpath)
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
|
||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
@ -16,6 +18,8 @@ func (r *DNSResolver) Matches(name string) bool {
|
||||
return strings.Contains(name, ".")
|
||||
}
|
||||
|
||||
// TXT records for a given domain name should contain a b58
|
||||
// encoded multihash.
|
||||
func (r *DNSResolver) Resolve(name string) (string, error) {
|
||||
txt, err := net.LookupTXT(name)
|
||||
if err != nil {
|
||||
@ -23,15 +27,17 @@ func (r *DNSResolver) Resolve(name string) (string, error) {
|
||||
}
|
||||
|
||||
for _, t := range txt {
|
||||
pair := strings.Split(t, "=")
|
||||
if len(pair) < 2 {
|
||||
// Log error?
|
||||
u.DErr("Incorrectly formatted text record.")
|
||||
chk := b58.Decode(t)
|
||||
if len(chk) == 0 {
|
||||
continue
|
||||
}
|
||||
if pair[0] == name {
|
||||
return pair[1], nil
|
||||
|
||||
_, err := mh.Cast(chk)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
return "", u.ErrNotFound
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package namesys
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
"code.google.com/p/goprotobuf/proto"
|
||||
|
||||
ci "github.com/jbenet/go-ipfs/crypto"
|
||||
@ -16,6 +17,7 @@ type IpnsPublisher struct {
|
||||
|
||||
// Publish accepts a keypair and a value,
|
||||
func (p *IpnsPublisher) Publish(k ci.PrivKey, value u.Key) error {
|
||||
ctx := context.TODO()
|
||||
data, err := CreateEntryData(k, value)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -38,13 +40,13 @@ func (p *IpnsPublisher) Publish(k ci.PrivKey, value u.Key) error {
|
||||
}
|
||||
|
||||
// Store associated public key
|
||||
err = p.routing.PutValue(u.Key(nameb), pkbytes)
|
||||
err = p.routing.PutValue(ctx, u.Key(nameb), pkbytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Store ipns entry at h("/ipns/"+b58(h(pubkey)))
|
||||
err = p.routing.PutValue(u.Key(ipnskey), data)
|
||||
err = p.routing.PutValue(ctx, u.Key(ipnskey), data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
bs "github.com/jbenet/go-ipfs/blockservice"
|
||||
ci "github.com/jbenet/go-ipfs/crypto"
|
||||
mdag "github.com/jbenet/go-ipfs/merkledag"
|
||||
"github.com/jbenet/go-ipfs/net/swarm"
|
||||
"github.com/jbenet/go-ipfs/peer"
|
||||
"github.com/jbenet/go-ipfs/routing/dht"
|
||||
"github.com/jbenet/go-ipfs/swarm"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
|
@ -2,8 +2,8 @@ package namesys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
"code.google.com/p/goprotobuf/proto"
|
||||
|
||||
ci "github.com/jbenet/go-ipfs/crypto"
|
||||
@ -11,8 +11,11 @@ import (
|
||||
"github.com/jbenet/go-ipfs/routing"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
mh "github.com/jbenet/go-multihash"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("namesys")
|
||||
|
||||
// RoutingResolver implements NSResolver for the main IPFS SFS-like naming
|
||||
type RoutingResolver struct {
|
||||
routing routing.IpfsRouting
|
||||
@ -32,9 +35,10 @@ func (r *RoutingResolver) Matches(name string) bool {
|
||||
}
|
||||
|
||||
func (r *RoutingResolver) Resolve(name string) (string, error) {
|
||||
ctx := context.TODO()
|
||||
hash, err := mh.FromB58String(name)
|
||||
if err != nil {
|
||||
u.DOut("RoutingResolve: bad input hash: [%s]\n", name)
|
||||
log.Warning("RoutingResolve: bad input hash: [%s]\n", name)
|
||||
return "", err
|
||||
}
|
||||
// name should be a multihash. if it isn't, error out here.
|
||||
@ -47,9 +51,9 @@ func (r *RoutingResolver) Resolve(name string) (string, error) {
|
||||
}
|
||||
|
||||
ipnsKey := u.Key(h)
|
||||
val, err := r.routing.GetValue(ipnsKey, time.Second*10)
|
||||
val, err := r.routing.GetValue(ctx, ipnsKey)
|
||||
if err != nil {
|
||||
u.DOut("RoutingResolve get failed.\n")
|
||||
log.Warning("RoutingResolve get failed.")
|
||||
return "", err
|
||||
}
|
||||
|
||||
@ -62,9 +66,9 @@ func (r *RoutingResolver) Resolve(name string) (string, error) {
|
||||
// name should be a public key retrievable from ipfs
|
||||
// /ipfs/<name>
|
||||
key := u.Key(hash)
|
||||
pkval, err := r.routing.GetValue(key, time.Second*10)
|
||||
pkval, err := r.routing.GetValue(ctx, key)
|
||||
if err != nil {
|
||||
u.DOut("RoutingResolve PubKey Get failed.\n")
|
||||
log.Warning("RoutingResolve PubKey Get failed.")
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -345,6 +345,7 @@ func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
|
||||
// Update signals to all routingTables to Update their last-seen status
|
||||
// on the given peer.
|
||||
func (dht *IpfsDHT) Update(p *peer.Peer) {
|
||||
u.DOut("updating peer: [%s] latency = %f\n", p.ID.Pretty(), p.GetLatency().Seconds())
|
||||
removedCount := 0
|
||||
for _, route := range dht.routingTables {
|
||||
removed := route.Update(p)
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
|
||||
// PutValue adds value corresponding to given Key.
|
||||
// This is the top level "Store" operation of the DHT
|
||||
func (dht *IpfsDHT) PutValue(key u.Key, value []byte) error {
|
||||
func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error {
|
||||
err := dht.putLocal(key, value)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -38,7 +38,7 @@ func (dht *IpfsDHT) PutValue(key u.Key, value []byte) error {
|
||||
return &dhtQueryResult{success: true}, nil
|
||||
})
|
||||
|
||||
_, err := query.Run(ctx, peers)
|
||||
_, err = query.Run(ctx, peers)
|
||||
u.DOut("[%s] PutValue %v %v\n", dht.self.ID.Pretty(), key, value)
|
||||
return err
|
||||
}
|
||||
@ -104,8 +104,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
|
||||
dht.providers.AddProvider(key, dht.self)
|
||||
peers := dht.routingTables[0].NearestPeers(kb.ConvertKey(key), PoolSize)
|
||||
if len(peers) == 0 {
|
||||
// Early out for no targets
|
||||
return nil
|
||||
return kb.ErrLookupFailure
|
||||
}
|
||||
|
||||
//TODO FIX: this doesn't work! it needs to be sent to the actual nearest peers.
|
||||
@ -156,12 +155,12 @@ func (dht *IpfsDHT) FindProvidersAsync2(ctx context.Context, key u.Key, count in
|
||||
peers := dht.routingTables[0].NearestPeers(kb.ConvertKey(key), AlphaValue)
|
||||
for _, pp := range peers {
|
||||
go func(p *peer.Peer) {
|
||||
pmes, err := dht.findProvidersSingle(p, key, 0, timeout)
|
||||
pmes, err := dht.findProvidersSingle(ctx, p, key, 0)
|
||||
if err != nil {
|
||||
u.PErr("%v\n", err)
|
||||
return
|
||||
}
|
||||
dht.addPeerListAsync(key, pmes.GetPeers(), ps, count, peerOut)
|
||||
dht.addPeerListAsync(key, pmes.GetProviderPeers(), ps, count, peerOut)
|
||||
}(pp)
|
||||
}
|
||||
|
||||
@ -190,11 +189,8 @@ func (dht *IpfsDHT) addPeerListAsync(k u.Key, peers []*Message_Peer, ps *peerSet
|
||||
|
||||
// FindProviders searches for peers who can provide the value for given key.
|
||||
func (dht *IpfsDHT) FindProviders(ctx context.Context, key u.Key) ([]*peer.Peer, error) {
|
||||
ll := startNewRPC("FindProviders")
|
||||
ll.EndAndPrint()
|
||||
|
||||
// get closest peer
|
||||
u.DOut("Find providers for: '%s'\n", key)
|
||||
u.DOut("Find providers for: '%s'\n", key.Pretty())
|
||||
p := dht.routingTables[0].NearestPeer(kb.ConvertKey(key))
|
||||
if p == nil {
|
||||
return nil, nil
|
||||
|
Reference in New Issue
Block a user