Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Patch go-multiaddr to handle backwards compatible cids
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Feb 4, 2019
1 parent 9aa8e6d commit e72c46f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
3 changes: 1 addition & 2 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ func (x *Start) Execute(args []string) error {
return errors.New("IPFS DHT routing is not configured")
}


// Get current directory root hash
ipnskey := namesys.IpnsDsKey(nd.Identity)
ival, hasherr := nd.Repo.Datastore().Get(ipnskey)
Expand Down Expand Up @@ -712,7 +711,7 @@ func (x *Start) Execute(args []string) error {
}()
}
}
<- core.Node.DHT.BootstrapChan
<-core.Node.DHT.BootstrapChan
core.Node.Service = service.New(core.Node, sqliteDB)

core.Node.StartMessageRetriever()
Expand Down
2 changes: 1 addition & 1 deletion ipfs/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ func TestIdentityKeyFromSeed(t *testing.T) {
if !bytes.Equal(key, keyBytes) {
t.Error("Failed to extract correct private key from seed")
}
}
}
4 changes: 2 additions & 2 deletions net/repointer/repointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const kRepointFrequency = time.Hour * 12
const kPointerExpiration = time.Hour * 24 * 30

type PointerRepublisher struct {
routing *dht.IpfsDHT
routing *dht.IpfsDHT
db repo.Datastore
pushNodes []peer.ID
isModerator func() bool
}

func NewPointerRepublisher(dht *dht.IpfsDHT, database repo.Datastore, pushNodes []peer.ID, isModerator func() bool) *PointerRepublisher {
return &PointerRepublisher{
routing: dht,
routing: dht,
db: database,
pushNodes: pushNodes,
isModerator: isModerator,
Expand Down
3 changes: 1 addition & 2 deletions net/retriever/retriever_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net

import (
"testing"

"github.com/OpenBazaar/openbazaar-go/pb"
"testing"
)

// TestEnsureNoOmissionsInMessageProcessingOrder ensures that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"context"
"crypto/rand"
"fmt"
"time"
"sync"
"time"

u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
goprocess "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
Expand Down Expand Up @@ -124,7 +124,9 @@ func (dht *IpfsDHT) bootstrapWorker(cfg BootstrapConfig) func(worker goprocess.P
}
}
}

var bootstrapOnce sync.Once

// runBootstrap builds up list of peers by requesting random peer IDs
func (dht *IpfsDHT) runBootstrap(ctx context.Context, cfg BootstrapConfig) error {
bslog := func(msg string) {
Expand Down Expand Up @@ -180,7 +182,7 @@ func (dht *IpfsDHT) runBootstrap(ctx context.Context, cfg BootstrapConfig) error
if len(merr) > 0 {
return merr
}
bootstrapOnce.Do(func(){
bootstrapOnce.Do(func() {
close(dht.BootstrapChan)
})
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ func sizeForAddr(p Protocol, b []byte) (skip, size int, err error) {
return 0, (p.Size / 8), nil
case p.Size == 0:
return 0, 0, nil
case p.Code == P_P2P:
// OpenBazaar: this has to be patched to handle cids in this field
// until most nodes on the network upgrade and we do not need this
// anymore.
if b[0] == 0x01 {
return 0, len(b), nil
} else if len(b) == 37 {
return 3, 34, nil
} else {
return 2, 34, nil
}

default:
size, n, err := ReadVarintCode(b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strconv"
"strings"

mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
)

type Transcoder interface {
Expand Down Expand Up @@ -189,8 +189,12 @@ func p2pStB(s string) ([]byte, error) {
}
}

// OpenBazaar: this has been patched to parse CIDs as well as multihashes
func p2pVal(b []byte) error {
_, err := mh.Cast(b)
_, err := cid.Cast(b)
if err != nil {
_, err = mh.Cast(b)
}
return err
}

Expand Down

0 comments on commit e72c46f

Please sign in to comment.