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

Commit

Permalink
Fix compatibility bugs in ipfs library
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Jan 30, 2019
1 parent cc5c139 commit 9aa8e6d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Restore struct {
}

func (x *Restore) Execute(args []string) error {
ipfscore.DHTOption = constructDHTRouting
reader := bufio.NewReader(os.Stdin)
if x.Mnemonic == "" {
fmt.Print("This command will override any current user data. Do you want to continue? (y/n): ")
Expand Down Expand Up @@ -146,6 +147,8 @@ func (x *Restore) Execute(args []string) error {
cfg.Bootstrap = testnetBootstrapAddrs
dhtopts.ProtocolDHT = "/openbazaar/kad/testnet/1.0.0"
bitswap.ProtocolBitswap = "/openbazaar/bitswap/testnet/1.1.0"
} else {
bitswap.ProtocolBitswap = "/openbazaar/bitswap/1.1.0"
}

cfg.Identity = identity
Expand Down Expand Up @@ -222,7 +225,6 @@ func (x *Restore) Execute(args []string) error {
"mplex": true,
"ipnsps": true,
},
Routing: DHTOption,
}
if onionTransport != nil {
ncfg.Host = defaultHostOption
Expand Down
6 changes: 3 additions & 3 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type Start struct {
}

func (x *Start) Execute(args []string) error {
ipfscore.DHTOption = constructDHTRouting
printSplashScreen(x.Verbose)

if x.Testnet && x.Regtest {
Expand Down Expand Up @@ -317,6 +318,8 @@ func (x *Start) Execute(args []string) error {
service.ProtocolOpenBazaar = "/openbazaar/app/testnet/1.0.0"

dataSharing.PushTo = []string{}
} else {
bitswap.ProtocolBitswap = "/openbazaar/bitswap/1.1.0"
}

onionAddr, err := obnet.MaybeCreateHiddenServiceKey(repoPath)
Expand Down Expand Up @@ -414,7 +417,6 @@ func (x *Start) Execute(args []string) error {
"mplex": true,
"ipnsps": true,
},
Routing: DHTOption,
}

if onionTransport != nil {
Expand Down Expand Up @@ -866,8 +868,6 @@ func newHTTPGateway(node *core.OpenBazaarNode, ctx commands.Context, authCookie
return api.NewGateway(node, authCookie, manet.NetListener(gwLis), config, ml, opts...)
}

var DHTOption ipfscore.RoutingOption = constructDHTRouting

const IpnsValidatorTag = "ipns"

func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore ds.Batching, validator record.Validator) (routing.IpfsRouting, error) {
Expand Down
3 changes: 1 addition & 2 deletions vendor/github.com/ipfs/go-ipfs/namesys/routing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ func (id ID) MatchesPrivateKey(sk ic.PrivKey) bool {
}

// MatchesPublicKey tests whether this ID was derived from pk
// OpenBazaar: test both inline and and hashes pubkeys.
func (id ID) MatchesPublicKey(pk ic.PubKey) bool {
oid, err := IDFromPublicKey(pk)
if err != nil {
return false
}
return oid == id
iid, err := InlineIDFromPublicKey(pk)
if err != nil {
return false
}
return oid == id || iid == id
}

// ExtractPublicKey attempts to extract the public key from an ID
Expand Down Expand Up @@ -144,6 +149,17 @@ func IDHexEncode(id ID) string {
return hex.EncodeToString([]byte(id))
}

// OpenBazaar: temporary helper function to remain forward compatible with
// inline keys
func InlineIDFromPublicKey(pk ic.PubKey) (ID, error) {
b, err := pk.Bytes()
if err != nil {
return "", err
}
hash, _ := mh.Sum(b, mh.ID, -1)
return ID(hash), nil
}

// IDFromPublicKey returns the Peer ID corresponding to pk
func IDFromPublicKey(pk ic.PubKey) (ID, error) {
b, err := pk.Bytes()
Expand All @@ -152,7 +168,9 @@ func IDFromPublicKey(pk ic.PubKey) (ID, error) {
}
var alg uint64 = mh.SHA2_256
if len(b) <= MaxInlineKeyLength {
alg = mh.ID
// OpenBazaar: in the next version once enough people have upgraded we will
// uncomment this line and generate inline keys.
//alg = mh.ID
}
hash, _ := mh.Sum(b, alg, -1)
return ID(hash), nil
Expand Down

0 comments on commit 9aa8e6d

Please sign in to comment.