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