From 83716af8905ba59a209271b98a893ca1a80e8ca3 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Wed, 5 Nov 2014 10:13:24 -0800 Subject: [PATCH 1/7] fix(bitswap) shut down async --- exchange/bitswap/bitswap.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 3ccab5d971d..369fcee7505 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -32,11 +32,9 @@ func NetMessageSession(ctx context.Context, p peer.Peer, notif := notifications.New() go func() { - for { - select { - case <-ctx.Done(): - notif.Shutdown() - } + select { + case <-ctx.Done(): + notif.Shutdown() } }() From e6ee19ed9279cb6ab513df4f0da7d9f068c1b28d Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Mon, 3 Nov 2014 03:01:58 -0800 Subject: [PATCH 2/7] feat(Dockerfile) use ENTRYPOINT Fixes #258 https://github.com/jbenet/go-ipfs/issues/258 --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 994bdd4dc2c..61234ed739a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,9 @@ RUN cd /go/src/github.com/jbenet/go-ipfs/cmd/ipfs && go install EXPOSE 4001 -CMD ["ipfs", "run"] +ENTRYPOINT ["ipfs"] + +CMD ["run"] # build: docker build -t go-ipfs . -# run: docker run -p 4001:4001 -e "IPFS_LOGGING=debug" go-ipfs:latest +# run: docker run -p 4001:4001 -e "IPFS_LOGGING=debug" go-ipfs:latest run From 67bc9cc89dda5e03c7dba1beb42a7216d5dea94c Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Mon, 3 Nov 2014 22:44:31 -0800 Subject: [PATCH 3/7] feat(init) display peer id in init command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit use case: Just configured and installed a node. benefits: 1) reduces friction when setting up a new node 2) reveals useful details about the workings of the system. It's the user's first encounter with her node's identity. The tour can build on the user's knowledge. ``` ipfs (maybebtc-november) λ. ipfs init -f initializing ipfs node at /Users/btc/.go-ipfs generating key pair peer identity: QmcRbn41Vc2CvbpLYfN36mAWusErKWvAAHbq92LPra2gFT ``` --- cmd/ipfs/init.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index 18fbaa134e0..6c1293d888f 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -125,6 +125,7 @@ func initCmd(c *commander.Command, inp []string) error { return err } cfg.Identity.PeerID = id.Pretty() + u.POut("peer identity: %s\n", id.Pretty()) // Use these hardcoded bootstrap peers for now. cfg.Bootstrap = []*config.BootstrapPeer{ From d3f9aadd3eb7b756f560d2cc598221884831a52d Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 4 Nov 2014 02:09:40 -0800 Subject: [PATCH 4/7] fix(commands/http/client) cast safely --- commands/http/client.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/commands/http/client.go b/commands/http/client.go index 9db9038db7a..748f5036513 100644 --- a/commands/http/client.go +++ b/commands/http/client.go @@ -3,6 +3,7 @@ package http import ( "bytes" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -12,6 +13,8 @@ import ( cmds "github.com/jbenet/go-ipfs/commands" ) +var castError = errors.New("cast error") + const ( ApiUrlFormat = "http://%s%s/%s?%s" ApiPath = "/api/v0" // TODO: make configurable @@ -33,11 +36,19 @@ func NewClient(address string) Client { func (c *client) Send(req cmds.Request) (cmds.Response, error) { var userEncoding string if enc, found := req.Option(cmds.EncShort); found { - userEncoding = enc.(string) + var ok bool + userEncoding, ok = enc.(string) + if !ok { + return nil, castError + } req.SetOption(cmds.EncShort, cmds.JSON) } else { + var ok bool enc, _ := req.Option(cmds.EncLong) - userEncoding = enc.(string) + userEncoding, ok = enc.(string) + if !ok { + return nil, castError + } req.SetOption(cmds.EncLong, cmds.JSON) } @@ -73,7 +84,11 @@ func getQuery(req cmds.Request) (string, io.Reader, error) { query := url.Values{} for k, v := range req.Options() { - query.Set(k, v.(string)) + str, ok := v.(string) + if !ok { + return "", nil, castError + } + query.Set(k, str) } args := req.Arguments() @@ -86,14 +101,22 @@ func getQuery(req cmds.Request) (string, io.Reader, error) { } if argDef.Type == cmds.ArgString { - query.Add("arg", arg.(string)) + str, ok := arg.(string) + if !ok { + return "", nil, castError + } + query.Add("arg", str) } else { // TODO: multipart if inputStream != nil { return "", nil, fmt.Errorf("Currently, only one file stream is possible per request") } - inputStream = arg.(io.Reader) + var ok bool + inputStream, ok = arg.(io.Reader) + if !ok { + return "", nil, castError + } } } From de170927adb790b9c4fe234fd253bcbd0144c58a Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 4 Nov 2014 02:12:02 -0800 Subject: [PATCH 5/7] fix(commands/request) cast safely should be able to look at a function in isolation and prove it won't panic. if that's not possible, should cast safely. --- commands/request.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/request.go b/commands/request.go index c26f1773bc4..40eda9fc6fd 100644 --- a/commands/request.go +++ b/commands/request.go @@ -1,6 +1,7 @@ package commands import ( + "errors" "fmt" "reflect" "strconv" @@ -116,7 +117,11 @@ func (r *request) ConvertOptions(options map[string]Option) error { if kind != opt.Type { if kind == String { convert := converters[opt.Type] - val, err := convert(v.(string)) + str, ok := v.(string) + if !ok { + return errors.New("cast error") + } + val, err := convert(str) if err != nil { return fmt.Errorf("Could not convert string value '%s' to type '%s'", v, opt.Type.String()) From 074722cf8aa343cf9ea6eac79d1eae6f70655461 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 4 Nov 2014 21:08:25 -0800 Subject: [PATCH 6/7] fix(peer) update latency --- peer/peer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/peer/peer.go b/peer/peer.go index 7cc8a4ccb90..6a5c8a2f60b 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -287,6 +287,8 @@ func (p *peer) Update(other Peer) error { p.AddAddress(a) } + p.SetLatency(other.GetLatency()) + sk := other.PrivKey() pk := other.PubKey() p.Lock() From 550b98b7fd60fa1b9dade392a5a634f854f131fb Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 4 Nov 2014 21:39:06 -0800 Subject: [PATCH 7/7] doc(peer) --- peer/peer.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/peer/peer.go b/peer/peer.go index 6a5c8a2f60b..14617dc2da3 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -56,6 +56,10 @@ type Map map[u.Key]Peer // Peer represents the identity information of an IPFS Node, including // ID, and relevant Addresses. type Peer interface { + + // TODO reduce the peer interface to be read-only. Force mutations to occur + // on the peer store eg. peerstore.SetLatency(peerId, value). + // ID returns the peer's ID ID() ID @@ -102,6 +106,8 @@ type peer struct { privKey ic.PrivKey pubKey ic.PubKey + // TODO move latency away from peer into the package that uses it. Instead, + // within that package, map from ID to latency value. latency time.Duration sync.RWMutex