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

Commit a4f9e6c

Browse files
committed
Merge master and fix conflicts
2 parents 0a5c9f8 + 296c3a6 commit a4f9e6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4723
-8138
lines changed

Godeps/Godeps.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/jsonapi.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525
ipnspath "gx/ipfs/QmQAgv6Gaoe2tQpcabqwKXKChp2MZ7i3UXv9DqTTaxCaTR/go-path"
2626
files "gx/ipfs/QmQmhotPUzVrMEWNK3x1R5jQ5ZHWyL7tVUrmRPjrBrvyCb/go-ipfs-files"
2727
cid "gx/ipfs/QmTbxNB1NwDesLmKTscr4udL2tVP7MaxvXnD1D9yX7g3PN/go-cid"
28-
datastore "gx/ipfs/QmUadX5EcvrBmxAV9sE7wUWtWSqxns5K84qKJBixmcT1w9/go-datastore"
2928
ipns "gx/ipfs/QmUwMnKKjH3JwGKNVZ3TcP37W93xzqNA4ECFFiMo6sXkkc/go-ipns"
3029
iface "gx/ipfs/QmXLwxifxwfc2bAwq6rdjbYqAsGzWsDE9RM5TWMGtykyj6/interface-go-ipfs-core"
3130
peer "gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer"
3231
routing "gx/ipfs/QmYxUdYY9S6yg5tSPVin5GFTvtfsLauVcr7reHDD3dM8xf/go-libp2p-routing"
3332
ps "gx/ipfs/QmaCTz9RkrU13bm9kMB54f7atgqM4qkjDZpRwRoJiWXEqs/go-libp2p-peerstore"
33+
ggproto "gx/ipfs/QmddjPSGZb3ieihSseFeCfVRpZzcqczPNsD2DvarSwnjJB/gogo-protobuf/proto"
3434
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
3535

3636
"github.com/OpenBazaar/jsonpb"
@@ -47,7 +47,6 @@ import (
4747
"github.com/golang/protobuf/ptypes"
4848
ipfscore "github.com/ipfs/go-ipfs/core"
4949
"github.com/ipfs/go-ipfs/core/coreapi"
50-
"github.com/ipfs/go-ipfs/namesys"
5150
"github.com/ipfs/go-ipfs/repo/fsrepo"
5251
)
5352

@@ -3877,6 +3876,7 @@ func (i *jsonAPIHandler) GETWalletStatus(w http.ResponseWriter, r *http.Request)
38773876
}
38783877

38793878
func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
3879+
ipfsStore := i.node.IpfsNode.Repo.Datastore()
38803880
_, peerID := path.Split(r.URL.Path)
38813881

38823882
pid, err := peer.IDB58Decode(peerID)
@@ -3885,7 +3885,7 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
38853885
return
38863886
}
38873887

3888-
val, err := i.node.IpfsNode.Repo.Datastore().Get(namesys.IpnsDsKey(pid))
3888+
peerIPNSRecord, err := ipfs.GetCachedIPNSRecord(ipfsStore, pid)
38893889
if err != nil { // No record in datastore
38903890
ErrorResponse(w, http.StatusNotFound, err.Error())
38913891
return
@@ -3894,7 +3894,7 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
38943894
var keyBytes []byte
38953895
pubkey := i.node.IpfsNode.Peerstore.PubKey(pid)
38963896
if pubkey == nil || !pid.MatchesPublicKey(pubkey) {
3897-
keyval, err := i.node.IpfsNode.Repo.Datastore().Get(datastore.NewKey(core.KeyCachePrefix + peerID))
3897+
keyval, err := ipfs.GetCachedPubkey(ipfsStore, peerID)
38983898
if err != nil {
38993899
ErrorResponse(w, http.StatusNotFound, err.Error())
39003900
return
@@ -3912,8 +3912,13 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
39123912
Pubkey string `json:"pubkey"`
39133913
Record string `json:"record"`
39143914
}
3915+
peerIPNSBytes, err := ggproto.Marshal(peerIPNSRecord)
3916+
if err != nil {
3917+
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("marshaling IPNS record: %s", err.Error()))
3918+
return
3919+
}
39153920

3916-
ret := KeyAndRecord{hex.EncodeToString(keyBytes), string(val)}
3921+
ret := KeyAndRecord{hex.EncodeToString(keyBytes), string(peerIPNSBytes)}
39173922
retBytes, err := json.MarshalIndent(ret, "", " ")
39183923
if err != nil {
39193924
ErrorResponse(w, http.StatusInternalServerError, err.Error())
@@ -3943,9 +3948,14 @@ func (i *jsonAPIHandler) GETResolveIPNS(w http.ResponseWriter, r *http.Request)
39433948
var response = respType{PeerID: peerID}
39443949

39453950
if i.node.IpfsNode.Identity.Pretty() == peerID {
3946-
ipnsBytes, err := i.node.IpfsNode.Repo.Datastore().Get(namesys.IpnsDsKey(i.node.IpfsNode.Identity))
3951+
rec, err := ipfs.GetCachedIPNSRecord(i.node.IpfsNode.Repo.Datastore(), i.node.IpfsNode.Identity)
3952+
if err != nil {
3953+
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("retrieving self: %s", err))
3954+
return
3955+
}
3956+
ipnsBytes, err := proto.Marshal(rec)
39473957
if err != nil {
3948-
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("retrieving self from datastore: %s", err))
3958+
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("marshaling self: %s", err))
39493959
return
39503960
}
39513961
response.Record.Hex = hex.EncodeToString(ipnsBytes)

api/jsonapi_test.go

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestProfile(t *testing.T) {
129129
})
130130
}
131131

132-
func TestProfileCurrencyUpdate(t *testing.T) {
132+
func TestPatchProfileCurrencyUpdate(t *testing.T) {
133133
var (
134134
postProfile = `{
135135
"handle": "test",
@@ -154,7 +154,7 @@ func TestProfileCurrencyUpdate(t *testing.T) {
154154
},
155155
"currencies": ["LTC"]
156156
}`
157-
putProfile = `{"currencies": ["ETH"]}`
157+
patchProfile = `{"currencies": ["ETH"]}`
158158
validateProfile = func(testRepo *test.Repository) error {
159159
m, err := schema.NewCustomSchemaManager(schema.SchemaContext{
160160
DataPath: testRepo.Path,
@@ -189,10 +189,76 @@ func TestProfileCurrencyUpdate(t *testing.T) {
189189

190190
runAPITestsWithSetup(t, apiTests{
191191
{"POST", "/ob/profile", postProfile, 200, anyResponseJSON},
192-
{"PATCH", "/ob/profile", putProfile, 200, anyResponseJSON},
192+
{"PATCH", "/ob/profile", patchProfile, 200, anyResponseJSON},
193193
}, nil, validateProfile)
194194
}
195195

196+
func TestPatchProfileCanBeInvalid(t *testing.T) {
197+
var (
198+
// init profile for patch
199+
postProfile = `{
200+
"handle": "test",
201+
"name": "Test User",
202+
"location": "Internet",
203+
"about": "The test fixture",
204+
"shortDescription": "Fixture",
205+
"contactInfo": {
206+
"website": "internet.com",
207+
"email": "[email protected]",
208+
"phoneNumber": "687-5309"
209+
},
210+
"nsfw": false,
211+
"vendor": false,
212+
"moderator": false,
213+
"colors": {
214+
"primary": "#000000",
215+
"secondary": "#FFD700",
216+
"text": "#ffffff",
217+
"highlight": "#123ABC",
218+
"highlightText": "#DEAD00"
219+
},
220+
"currencies": ["LTC"]
221+
}`
222+
// test valid patch
223+
patchProfile = `{
224+
"moderator": true,
225+
"moderatorInfo": {
226+
"description": "Fix plus percentage. Test moderator account. DO NOT USE.",
227+
"fee": {
228+
"feeType": "FIXED_PLUS_PERCENTAGE",
229+
"fixedFee": {
230+
"amountCurrency": {
231+
"code": "USD",
232+
"divisibility": 2
233+
},
234+
"bigAmount": "2"
235+
},
236+
"percentage": 0.1
237+
},
238+
"languages": [
239+
"en-US"
240+
],
241+
"termsAndConditions": "Test moderator account. DO NOT USE."
242+
}
243+
}`
244+
// test invalid patch: percentage must be greater than 0
245+
invalidPatchProfile = `{
246+
"moderatorInfo": {
247+
"fee": {
248+
"percentage": -1
249+
}
250+
}
251+
}`
252+
)
253+
254+
expectedErr := fmt.Errorf("invalid profile: %s", repo.ErrModeratorFeeHasNegativePercentage)
255+
runAPITests(t, apiTests{
256+
{"POST", "/ob/profile", postProfile, 200, anyResponseJSON},
257+
{"PATCH", "/ob/profile", patchProfile, 200, anyResponseJSON},
258+
{"PATCH", "/ob/profile", invalidPatchProfile, 500, errorResponseJSON(expectedErr)},
259+
})
260+
}
261+
196262
func TestAvatar(t *testing.T) {
197263
// Setting an avatar fails if we don't have a profile
198264
runAPITests(t, apiTests{
@@ -512,7 +578,7 @@ func TestCryptoListingsQuantity(t *testing.T) {
512578
"POST", "/ob/listing", jsonFor(t, listing), 200, `{"slug": "crypto"}`,
513579
})
514580

515-
listing.Item.Skus[0].BigQuantity = "0"
581+
listing.Item.Skus[0].BigQuantity = "-1"
516582
runAPITest(t, apiTest{
517583
"POST", "/ob/listing", jsonFor(t, listing), 500, errorResponseJSON(repo.ErrCryptocurrencySkuQuantityInvalid),
518584
})

cmd/start.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import (
2323
dht "gx/ipfs/QmSY3nkMNLzh9GdbFKK5tT7YMfLpf52iUZ8ZRkr29MJaa5/go-libp2p-kad-dht"
2424
ma "gx/ipfs/QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL/go-multiaddr"
2525
config "gx/ipfs/QmUAuYuiafnJRZxDDX7MuruMNsicYNuyub5vUeAcupUBNs/go-ipfs-config"
26-
ipnspb "gx/ipfs/QmUwMnKKjH3JwGKNVZ3TcP37W93xzqNA4ECFFiMo6sXkkc/go-ipns/pb"
2726
peer "gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer"
2827
oniontp "gx/ipfs/QmYv2MbwHn7qcvAPFisZ94w85crQVpwUuv8G7TuUeBnfPb/go-onion-transport"
2928
ipfslogging "gx/ipfs/QmbkT7eMTyXfpeyB3ZMxxcxg7XH8t6uXp49jqzz4HB7BGF/go-log/writer"
3029
manet "gx/ipfs/Qmc85NSvmSG4Frn9Vb2cBc1rMyULH6D3TNVEfCzSKoUpip/go-multiaddr-net"
31-
proto "gx/ipfs/QmddjPSGZb3ieihSseFeCfVRpZzcqczPNsD2DvarSwnjJB/gogo-protobuf/proto"
3230

3331
"github.com/OpenBazaar/openbazaar-go/api"
3432
"github.com/OpenBazaar/openbazaar-go/core"
@@ -53,7 +51,6 @@ import (
5351
"github.com/ipfs/go-ipfs/commands"
5452
ipfscore "github.com/ipfs/go-ipfs/core"
5553
"github.com/ipfs/go-ipfs/core/corehttp"
56-
"github.com/ipfs/go-ipfs/namesys"
5754
"github.com/ipfs/go-ipfs/repo/fsrepo"
5855
"github.com/natefinch/lumberjack"
5956
"github.com/op/go-logging"
@@ -407,43 +404,27 @@ func (x *Start) Execute(args []string) error {
407404
}
408405
var dhtRouting *dht.IpfsDHT
409406
for _, router := range tiered.Routers {
410-
if r, ok := router.(*ipfs.CachingRouter); ok {
411-
r.APIRouter().Start(torDialer)
412-
dhtRouting, err = r.DHT()
413-
if err != nil {
414-
return err
415-
}
416-
} else if x.Regtest {
417-
if r, ok := router.(*dht.IpfsDHT); ok {
418-
dhtRouting = r
419-
}
407+
if r, ok := router.(*dht.IpfsDHT); ok {
408+
dhtRouting = r
420409
}
421410
}
422411
if dhtRouting == nil {
423412
return errors.New("IPFS DHT routing is not configured")
424413
}
425414

426415
// Get current directory root hash
427-
ipnskey := namesys.IpnsDsKey(nd.Identity)
428-
ival, hasherr := nd.Repo.Datastore().Get(ipnskey)
416+
cachedIPNSRecord, hasherr := ipfs.GetCachedIPNSRecord(nd.Repo.Datastore(), nd.Identity)
429417
if hasherr != nil {
430-
log.Error("get ipns key:", hasherr)
431-
}
432-
ourIpnsRecord := new(ipnspb.IpnsEntry)
433-
err = proto.Unmarshal(ival, ourIpnsRecord)
434-
if err != nil {
435-
log.Error("unmarshal record value", err)
436-
err = nd.Repo.Datastore().Delete(ipnskey)
437-
if err != nil {
438-
log.Error(err)
418+
log.Warning(err)
419+
if err := ipfs.DeleteCachedIPNSRecord(nd.Repo.Datastore(), nd.Identity); err != nil {
420+
log.Errorf("deleting invalid IPNS record: %s", err.Error())
439421
}
440422
}
441423

442424
if x.ForceKeyCachePurge {
443425
log.Infof("forcing key purge from namesys cache...")
444-
err = nd.Repo.Datastore().Delete(ipnskey)
445-
if err != nil {
446-
log.Error(err)
426+
if err := ipfs.DeleteCachedIPNSRecord(nd.Repo.Datastore(), nd.Identity); err != nil {
427+
log.Errorf("force-purging IPNS record: %s", err.Error())
447428
}
448429
}
449430

@@ -597,6 +578,11 @@ func (x *Start) Execute(args []string) error {
597578
subscriber := ipfs.NewPubsubSubscriber(context.Background(), nd.PeerHost, nd.Routing, nd.Repo.Datastore(), nd.PubSub)
598579
ps := ipfs.Pubsub{Publisher: publisher, Subscriber: subscriber}
599580

581+
var rootHash string
582+
if cachedIPNSRecord != nil {
583+
rootHash = string(cachedIPNSRecord.Value)
584+
}
585+
600586
// OpenBazaar node setup
601587
core.Node = &core.OpenBazaarNode{
602588
AcceptStoreRequests: dataSharing.AcceptStoreRequests,
@@ -611,7 +597,7 @@ func (x *Start) Execute(args []string) error {
611597
PushNodes: pushNodes,
612598
RegressionTestEnable: x.Regtest,
613599
RepoPath: repoPath,
614-
RootHash: string(ourIpnsRecord.Value),
600+
RootHash: rootHash,
615601
TestnetEnable: x.Testnet,
616602
TorDialer: torDialer,
617603
UserAgent: core.USERAGENT,
@@ -697,6 +683,7 @@ func (x *Start) Execute(args []string) error {
697683
core.Node.StartMessageRetriever()
698684
core.Node.StartPointerRepublisher()
699685
core.Node.StartRecordAgingNotifier()
686+
core.Node.StartInboundMsgScanner()
700687

701688
core.Node.PublishLock.Unlock()
702689
err = core.Node.UpdateFollow()

core/core.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
libp2p "gx/ipfs/QmTW4SdgBWq9GjsBsHeUx8WuGxzhgzAf88UMH2w62PC8yK/go-libp2p-crypto"
88
ma "gx/ipfs/QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL/go-multiaddr"
99
cid "gx/ipfs/QmTbxNB1NwDesLmKTscr4udL2tVP7MaxvXnD1D9yX7g3PN/go-cid"
10-
"gx/ipfs/QmUadX5EcvrBmxAV9sE7wUWtWSqxns5K84qKJBixmcT1w9/go-datastore"
1110
peer "gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer"
1211
routing "gx/ipfs/QmYxUdYY9S6yg5tSPVin5GFTvtfsLauVcr7reHDD3dM8xf/go-libp2p-routing"
1312

@@ -31,7 +30,7 @@ import (
3130

3231
const (
3332
// VERSION - current version
34-
VERSION = "0.13.5"
33+
VERSION = "0.13.6"
3534
// USERAGENT - user-agent header string
3635
USERAGENT = "/openbazaar-go:" + VERSION + "/"
3736
)
@@ -121,6 +120,10 @@ type OpenBazaarNode struct {
121120
seedLock sync.Mutex
122121

123122
InitalPublishComplete bool
123+
124+
// InboundMsgScanner is a worker that scans the messages
125+
// table and tries to retry a failed order message
126+
InboundMsgScanner *inboundMessageScanner
124127
}
125128

126129
// TestNetworkEnabled indicates whether the node is operating with test parameters
@@ -278,8 +281,11 @@ func (n *OpenBazaarNode) EncryptMessage(peerID peer.ID, peerKey *libp2p.PubKey,
278281
ctx, cancel := context.WithTimeout(context.Background(), n.OfflineMessageFailoverTimeout)
279282
defer cancel()
280283
if peerKey == nil {
281-
var pubKey libp2p.PubKey
282-
keyval, err := n.IpfsNode.Repo.Datastore().Get(datastore.NewKey(KeyCachePrefix + peerID.Pretty()))
284+
var (
285+
pubKey libp2p.PubKey
286+
store = n.IpfsNode.Repo.Datastore()
287+
)
288+
keyval, err := ipfs.GetCachedPubkey(store, peerID.Pretty())
283289
if err != nil {
284290
pubKey, err = routing.GetPublicKey(n.IpfsNode.Routing, ctx, peerID)
285291
if err != nil {

0 commit comments

Comments
 (0)