Skip to content

Commit

Permalink
Merge pull request #267 from jbenet/maybebtc-november
Browse files Browse the repository at this point in the history
Miscellaneous fixes
  • Loading branch information
jbenet committed Nov 7, 2014
2 parents 62f1614 + 550b98b commit 3155fa2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
33 changes: 28 additions & 5 deletions commands/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package http
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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()
Expand All @@ -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
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion commands/request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"errors"
"fmt"
"reflect"
"strconv"
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 3 additions & 5 deletions exchange/bitswap/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}()

Expand Down
8 changes: 8 additions & 0 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3155fa2

Please sign in to comment.