catch ipns branch up to master and make all things compile
Jeromy committed
Sep 22, 2014 at 15:14 UTC
a65e8600a3e40c0238db17eac0fe0eb71bb1b7cd
12 files changed
+68
-42
cmd/ipfs/ipfs.go
-1
@@ -4,7 +4,6 @@ import (
4
"errors"
5
"fmt"
6
"os"
7
- "runtime"
7
8
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
9
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
cmd/ipfs/pin.go
+13
-8
@@ -3,8 +3,9 @@ package main
3
import (
4
"os"
5
6
- "github.com/gonuts/flag"
7
- "github.com/jbenet/commander"
6
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
7
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
+ "github.com/jbenet/go-ipfs/core/commands"
9
"github.com/jbenet/go-ipfs/daemon"
10
u "github.com/jbenet/go-ipfs/util"
11
)
@@ -27,18 +28,22 @@ func pinCmd(c *commander.Command, inp []string) error {
28
return nil
29
}
30
30
- com := daemon.NewCommand()
31
- com.Command = "pin"
32
- com.Args = inp
31
+ cmd := daemon.NewCommand()
32
+ cmd.Command = "pin"
33
+ cmd.Args = inp
34
34
- err := daemon.SendCommand(com, "localhost:12345")
35
+ err := daemon.SendCommand(cmd, "localhost:12345")
36
if err != nil {
36
- n, err := localNode(false)
37
+ conf, err := getConfigDir(c.Parent)
38
+ if err != nil {
39
+ return err
40
+ }
41
+ n, err := localNode(conf, false)
42
if err != nil {
43
return err
44
}
45
41
- daemon.ExecuteCommand(com, n, os.Stdout)
46
+ return commands.Pin(n, cmd.Args, cmd.Opts, os.Stdout)
47
}
48
return nil
49
}
cmd/ipfs/run.go
+19
-2
@@ -1,8 +1,11 @@
1
package main
2
3
import (
4
+ "errors"
5
+
6
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
7
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
+ ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
9
"github.com/jbenet/go-ipfs/daemon"
10
u "github.com/jbenet/go-ipfs/util"
11
)
@@ -19,12 +22,26 @@ var cmdIpfsRun = &commander.Command{
22
func runCmd(c *commander.Command, inp []string) error {
23
u.Debug = true
24
22
- n, err := localNode(true)
25
+ conf, err := getConfigDir(c.Parent)
26
+ if err != nil {
27
+ return err
28
+ }
29
+ n, err := localNode(conf, true)
30
+ if err != nil {
31
+ return err
32
+ }
33
+
34
+ // launch the RPC endpoint.
35
+ if n.Config.RPCAddress == "" {
36
+ return errors.New("no config.RPCAddress endpoint supplied")
37
+ }
38
+
39
+ maddr, err := ma.NewMultiaddr(n.Config.RPCAddress)
40
if err != nil {
41
return err
42
}
43
27
- dl, err := daemon.NewDaemonListener(n, "localhost:12345")
44
+ dl, err := daemon.NewDaemonListener(n, maddr)
45
if err != nil {
46
return err
47
}
crypto/spipe/handshake.go
+1
-4
@@ -229,8 +229,7 @@ func (s *SecurePipe) handleSecureIn(hashType string, tIV, tCKey, tMKey []byte) {
229
for {
230
data, ok := <-s.insecure.In
231
if !ok {
232
- u.DOut("Closing incoming proxy.\n")
233
- close(s.In)
232
+ close(s.Duplex.In)
233
return
234
}
235
@@ -267,8 +266,6 @@ func (s *SecurePipe) handleSecureOut(hashType string, mIV, mCKey, mMKey []byte)
266
for {
267
data, ok := <-s.Out
268
if !ok {
270
- u.DOut("Closing outgoing proxy.\n")
271
- close(s.Out)
269
return
270
}
271
crypto/spipe/pipe.go
-1
@@ -82,6 +82,5 @@ func (s *SecurePipe) Close() error {
82
83
s.cancel()
84
s.cancel = nil
85
- close(s.In)
85
return nil
86
}
fuse/readonly/readonly_unix.go
+1
-1
@@ -168,7 +168,7 @@ func Mount(ipfs *core.IpfsNode, fpath string) error {
168
}
169
time.Sleep(time.Millisecond * 10)
170
}
171
- ipfs.Swarm.Close()
171
+ ipfs.Network.Close()
172
}()
173
174
c, err := fuse.Mount(fpath)
namesys/dns.go
+12
-6
@@ -4,6 +4,8 @@ import (
4
"net"
5
"strings"
6
7
+ b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
8
+ mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
9
u "github.com/jbenet/go-ipfs/util"
10
)
11
@@ -16,6 +18,8 @@ func (r *DNSResolver) Matches(name string) bool {
18
return strings.Contains(name, ".")
19
}
20
21
+// TXT records for a given domain name should contain a b58
22
+// encoded multihash.
23
func (r *DNSResolver) Resolve(name string) (string, error) {
24
txt, err := net.LookupTXT(name)
25
if err != nil {
@@ -23,15 +27,17 @@ func (r *DNSResolver) Resolve(name string) (string, error) {
27
}
28
29
for _, t := range txt {
26
- pair := strings.Split(t, "=")
27
- if len(pair) < 2 {
28
- // Log error?
29
- u.DErr("Incorrectly formatted text record.")
30
+ chk := b58.Decode(t)
31
+ if len(chk) == 0 {
32
continue
33
}
32
- if pair[0] == name {
33
- return pair[1], nil
34
+
35
+ _, err := mh.Cast(chk)
36
+ if err != nil {
37
+ continue
38
}
39
+ return t, nil
40
}
41
+
42
return "", u.ErrNotFound
43
}
namesys/publisher.go
+4
-2
@@ -1,6 +1,7 @@
1
package namesys
2
3
import (
4
+ "code.google.com/p/go.net/context"
5
"code.google.com/p/goprotobuf/proto"
6
7
ci "github.com/jbenet/go-ipfs/crypto"
@@ -16,6 +17,7 @@ type IpnsPublisher struct {
17
18
// Publish accepts a keypair and a value,
19
func (p *IpnsPublisher) Publish(k ci.PrivKey, value u.Key) error {
20
+ ctx := context.TODO()
21
data, err := CreateEntryData(k, value)
22
if err != nil {
23
return err
@@ -38,13 +40,13 @@ func (p *IpnsPublisher) Publish(k ci.PrivKey, value u.Key) error {
40
}
41
42
// Store associated public key
41
- err = p.routing.PutValue(u.Key(nameb), pkbytes)
43
+ err = p.routing.PutValue(ctx, u.Key(nameb), pkbytes)
44
if err != nil {
45
return err
46
}
47
48
// Store ipns entry at h("/ipns/"+b58(h(pubkey)))
47
- err = p.routing.PutValue(u.Key(ipnskey), data)
49
+ err = p.routing.PutValue(ctx, u.Key(ipnskey), data)
50
if err != nil {
51
return err
52
}
namesys/resolve_test.go
+1
-1
@@ -7,9 +7,9 @@ import (
7
bs "github.com/jbenet/go-ipfs/blockservice"
8
ci "github.com/jbenet/go-ipfs/crypto"
9
mdag "github.com/jbenet/go-ipfs/merkledag"
10
+ "github.com/jbenet/go-ipfs/net/swarm"
11
"github.com/jbenet/go-ipfs/peer"
12
"github.com/jbenet/go-ipfs/routing/dht"
12
- "github.com/jbenet/go-ipfs/swarm"
13
u "github.com/jbenet/go-ipfs/util"
14
)
15
namesys/routing.go
+10
-6
@@ -2,8 +2,8 @@ package namesys
2
3
import (
4
"fmt"
5
- "time"
5
6
+ "code.google.com/p/go.net/context"
7
"code.google.com/p/goprotobuf/proto"
8
9
ci "github.com/jbenet/go-ipfs/crypto"
@@ -11,8 +11,11 @@ import (
11
"github.com/jbenet/go-ipfs/routing"
12
u "github.com/jbenet/go-ipfs/util"
13
mh "github.com/jbenet/go-multihash"
14
+ "github.com/op/go-logging"
15
)
16
17
+var log = logging.MustGetLogger("namesys")
18
+
19
// RoutingResolver implements NSResolver for the main IPFS SFS-like naming
20
type RoutingResolver struct {
21
routing routing.IpfsRouting
@@ -32,9 +35,10 @@ func (r *RoutingResolver) Matches(name string) bool {
35
}
36
37
func (r *RoutingResolver) Resolve(name string) (string, error) {
38
+ ctx := context.TODO()
39
hash, err := mh.FromB58String(name)
40
if err != nil {
37
- u.DOut("RoutingResolve: bad input hash: [%s]\n", name)
41
+ log.Warning("RoutingResolve: bad input hash: [%s]\n", name)
42
return "", err
43
}
44
// name should be a multihash. if it isn't, error out here.
@@ -47,9 +51,9 @@ func (r *RoutingResolver) Resolve(name string) (string, error) {
51
}
52
53
ipnsKey := u.Key(h)
50
- val, err := r.routing.GetValue(ipnsKey, time.Second*10)
54
+ val, err := r.routing.GetValue(ctx, ipnsKey)
55
if err != nil {
52
- u.DOut("RoutingResolve get failed.\n")
56
+ log.Warning("RoutingResolve get failed.")
57
return "", err
58
}
59
@@ -62,9 +66,9 @@ func (r *RoutingResolver) Resolve(name string) (string, error) {
66
// name should be a public key retrievable from ipfs
67
// /ipfs/<name>
68
key := u.Key(hash)
65
- pkval, err := r.routing.GetValue(key, time.Second*10)
69
+ pkval, err := r.routing.GetValue(ctx, key)
70
if err != nil {
67
- u.DOut("RoutingResolve PubKey Get failed.\n")
71
+ log.Warning("RoutingResolve PubKey Get failed.")
72
return "", err
73
}
74
routing/dht/dht.go
+1
@@ -345,6 +345,7 @@ func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
345
// Update signals to all routingTables to Update their last-seen status
346
// on the given peer.
347
func (dht *IpfsDHT) Update(p *peer.Peer) {
348
+ u.DOut("updating peer: [%s] latency = %f\n", p.ID.Pretty(), p.GetLatency().Seconds())
349
removedCount := 0
350
for _, route := range dht.routingTables {
351
removed := route.Update(p)
routing/dht/routing.go
+6
-10
@@ -17,7 +17,7 @@ import (
17
18
// PutValue adds value corresponding to given Key.
19
// This is the top level "Store" operation of the DHT
20
-func (dht *IpfsDHT) PutValue(key u.Key, value []byte) error {
20
+func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error {
21
err := dht.putLocal(key, value)
22
if err != nil {
23
return err
@@ -38,7 +38,7 @@ func (dht *IpfsDHT) PutValue(key u.Key, value []byte) error {
38
return &dhtQueryResult{success: true}, nil
39
})
40
41
- _, err := query.Run(ctx, peers)
41
+ _, err = query.Run(ctx, peers)
42
u.DOut("[%s] PutValue %v %v\n", dht.self.ID.Pretty(), key, value)
43
return err
44
}
@@ -104,8 +104,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
104
dht.providers.AddProvider(key, dht.self)
105
peers := dht.routingTables[0].NearestPeers(kb.ConvertKey(key), PoolSize)
106
if len(peers) == 0 {
107
- // Early out for no targets
108
- return nil
107
+ return kb.ErrLookupFailure
108
}
109
110
//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
155
peers := dht.routingTables[0].NearestPeers(kb.ConvertKey(key), AlphaValue)
156
for _, pp := range peers {
157
go func(p *peer.Peer) {
159
- pmes, err := dht.findProvidersSingle(p, key, 0, timeout)
158
+ pmes, err := dht.findProvidersSingle(ctx, p, key, 0)
159
if err != nil {
160
u.PErr("%v\n", err)
161
return
162
}
164
- dht.addPeerListAsync(key, pmes.GetPeers(), ps, count, peerOut)
163
+ dht.addPeerListAsync(key, pmes.GetProviderPeers(), ps, count, peerOut)
164
}(pp)
165
}
166
@@ -190,11 +189,8 @@ func (dht *IpfsDHT) addPeerListAsync(k u.Key, peers []*Message_Peer, ps *peerSet
189
190
// FindProviders searches for peers who can provide the value for given key.
191
func (dht *IpfsDHT) FindProviders(ctx context.Context, key u.Key) ([]*peer.Peer, error) {
193
- ll := startNewRPC("FindProviders")
194
- ll.EndAndPrint()
195
-
192
// get closest peer
197
- u.DOut("Find providers for: '%s'\n", key)
193
+ u.DOut("Find providers for: '%s'\n", key.Pretty())
194
p := dht.routingTables[0].NearestPeer(kb.ConvertKey(key))
195
if p == nil {
196
return nil, nil