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 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{ 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 + } } } 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()) 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() } }() diff --git a/peer/peer.go b/peer/peer.go index 7cc8a4ccb90..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 @@ -287,6 +293,8 @@ func (p *peer) Update(other Peer) error { p.AddAddress(a) } + p.SetLatency(other.GetLatency()) + sk := other.PrivKey() pk := other.PubKey() p.Lock()