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

Commit 755e025

Browse files
authored
Merge pull request #2067 from OpenBazaar/chrisfixes
Merge in some changes from that were in the mobile branch
2 parents f3f0b76 + fc05296 commit 755e025

File tree

9 files changed

+88
-71
lines changed

9 files changed

+88
-71
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ help:
2222

2323
.PHONY: ios_framework
2424
ios_framework: ## Build iOS Framework for mobile
25-
gomobile bind -target=ios github.com/OpenBazaar/openbazaar-go/mobile
25+
gomobile bind -target=ios/arm64,ios/amd64 -iosversion=10 -ldflags="-s -w" github.com/OpenBazaar/openbazaar-go/mobile
2626

2727
.PHONY: android_framework
2828
android_framework: ## Build Android Framework for mobile
29-
gomobile bind -target=android github.com/OpenBazaar/openbazaar-go/mobile
29+
gomobile bind -target=android/arm,android/arm64,android/amd64 -ldflags="-s -w" github.com/OpenBazaar/openbazaar-go/mobile
3030

3131
##
3232
## Protobuf compilation

core/core.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (n *OpenBazaarNode) retryableSeedStoreToPeer(pid peer.ID, graphHash string,
265265
}
266266
err := n.SendStore(pid.Pretty(), graph)
267267
if err != nil {
268-
if retryTimeout > 60*time.Second {
268+
if retryTimeout > 8*time.Second {
269269
log.Errorf("error pushing to peer %s: %s", pid.Pretty(), err.Error())
270270
return
271271
}

core/net.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,32 @@ func (n *OpenBazaarNode) SendOfflineMessage(p peer.ID, k *libp2p.PubKey, m *pb.M
9898
}
9999
}
100100
log.Debugf("Sending offline message to: %s, Message Type: %s, PointerID: %s, Location: %s", p.Pretty(), m.MessageType.String(), pointer.Cid.String(), pointer.Value.Addrs[0].String())
101-
OfflineMessageWaitGroup.Add(2)
102-
go func() {
103-
ctx, cancel := context.WithCancel(context.Background())
104-
defer cancel()
105-
err := ipfs.PublishPointer(n.DHT, ctx, pointer)
106-
if err != nil {
107-
log.Error(err)
108-
}
109101

110-
// Push provider to our push nodes for redundancy
111-
for _, p := range n.PushNodes {
102+
// We publish our pointers to three different locations:
103+
// 1. The pushnodes
104+
// 2. The DHT
105+
// 3. Pubsub
106+
// Each one is done in a separate goroutine so as to not block but we
107+
// do increment the OfflineMessageWaitGroup which is used to block
108+
// shutdown until all publishing is finished.
109+
OfflineMessageWaitGroup.Add(2 + len(n.PushNodes))
110+
for _, p := range n.PushNodes {
111+
go func(pid peer.ID) {
112112
ctx, cancel := context.WithCancel(context.Background())
113113
defer cancel()
114-
err := ipfs.PutPointerToPeer(n.DHT, ctx, p, pointer)
114+
err := ipfs.PutPointerToPeer(n.DHT, ctx, pid, pointer)
115115
if err != nil {
116116
log.Error(err)
117117
}
118+
OfflineMessageWaitGroup.Done()
119+
}(p)
120+
}
121+
go func() {
122+
ctx, cancel := context.WithCancel(context.Background())
123+
defer cancel()
124+
err := ipfs.PublishPointer(n.DHT, ctx, pointer)
125+
if err != nil {
126+
log.Error(err)
118127
}
119128

120129
OfflineMessageWaitGroup.Done()

mobile/cmd/main.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package main
22

33
import (
44
"fmt"
5-
"os"
6-
"sync"
7-
"time"
8-
95
"github.com/OpenBazaar/openbazaar-go/mobile"
106
"github.com/jessevdk/go-flags"
7+
"os"
8+
"path"
119
)
1210

1311
type Options struct {
@@ -21,7 +19,7 @@ var (
2119
)
2220

2321
func main() {
24-
var dataPath = "/Users/mg/work/ob/openbazaar-go/config_mobile_test"
22+
var dataPath = path.Join(os.TempDir(), "ob-mobile")
2523
if _, err := parser.Parse(); err != nil {
2624
if len(os.Args) > 1 && os.Args[1] == "-h" {
2725
os.Exit(0)
@@ -35,7 +33,6 @@ func main() {
3533
}
3634

3735
var (
38-
wg sync.WaitGroup
3936
n, err = mobile.NewNodeWithConfig(&mobile.NodeConfig{
4037
RepoPath: dataPath,
4138
Testnet: options.TestnetEnabled,
@@ -48,18 +45,5 @@ func main() {
4845
fmt.Println(err.Error())
4946
}
5047

51-
time.Sleep(time.Second * 10)
52-
fmt.Println("restarting...", time.Now())
53-
54-
wg.Add(1)
55-
56-
go func() {
57-
err := n.Restart()
58-
if err != nil {
59-
panic(fmt.Sprintf("failed to restart: %s", err.Error()))
60-
}
61-
}()
62-
63-
wg.Wait()
64-
48+
select {}
6549
}

mobile/node.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type Node struct {
7070

7171
var (
7272
fileLogFormat = logging.MustStringFormatter(
73-
`%{time:2006-01-02 15:04:05.000} [%{level}] [%{module}/%{shortfunc}] %{message}`,
73+
`[Haven] %{time:2006-01-02 15:04:05.000} [%{level}] [%{module}/%{shortfunc}] %{message}`,
7474
)
7575
publishUnlocked = false
7676
mainLoggingBackend logging.Backend
@@ -122,7 +122,9 @@ func NewNodeWithConfig(config *NodeConfig, password string, mnemonic string) (*N
122122
}
123123
obFileBackend := logging.NewLogBackend(obLog, "", 0)
124124
obFileBackendFormatted := logging.NewBackendFormatter(obFileBackend, fileLogFormat)
125-
mainLoggingBackend = logging.SetBackend(obFileBackendFormatted)
125+
stdoutBackend := logging.NewLogBackend(os.Stdout, "", 0)
126+
stdoutBackendFormatted := logging.NewBackendFormatter(stdoutBackend, fileLogFormat)
127+
mainLoggingBackend = logging.SetBackend(obFileBackendFormatted, stdoutBackendFormatted)
126128
logging.SetLevel(logging.INFO, "")
127129

128130
sqliteDB, err := initializeRepo(config.RepoPath, "", "", true, time.Now(), wi.Bitcoin)
@@ -282,7 +284,7 @@ func NewNodeWithConfig(config *NodeConfig, password string, mnemonic string) (*N
282284
Datastore: sqliteDB,
283285
MasterPrivateKey: mPrivKey,
284286
Multiwallet: mw,
285-
OfflineMessageFailoverTimeout: 5 * time.Second,
287+
OfflineMessageFailoverTimeout: 3 * time.Second,
286288
PushNodes: pushNodes,
287289
RepoPath: config.RepoPath,
288290
UserAgent: core.USERAGENT,
@@ -324,6 +326,13 @@ func (n *Node) startIPFSNode(repoPath string, config *ipfscore.BuildCfg) (*ipfsc
324326
n.cancel = cancel
325327

326328
ctx := commands.Context{}
329+
330+
ipfscore.DefaultBootstrapConfig = ipfscore.BootstrapConfig{
331+
MinPeerThreshold: 8,
332+
Period: time.Second * 10,
333+
ConnectionTimeout: time.Second * 10 / 3,
334+
}
335+
327336
nd, err := ipfscore.NewNode(cctx, config)
328337
if err != nil {
329338
return nil, ctx, err

net/retriever/retriever.go

+34-30
Original file line numberDiff line numberDiff line change
@@ -91,66 +91,70 @@ func NewMessageRetriever(cfg MRConfig) *MessageRetriever {
9191
WaitGroup: new(sync.WaitGroup),
9292
}
9393

94-
mr.Add(1)
94+
mr.Add(2)
9595
return &mr
9696
}
9797

9898
func (m *MessageRetriever) Run() {
9999
dht := time.NewTicker(time.Hour)
100-
peers := time.NewTicker(time.Minute * 10)
100+
peers := time.NewTicker(time.Minute)
101101
defer dht.Stop()
102102
defer peers.Stop()
103-
go m.fetchPointers(true)
103+
go m.fetchPointersFromDHT()
104+
go m.fetchPointersFromPushNodes()
104105
for {
105106
select {
106107
case <-dht.C:
107108
m.Add(1)
108-
go m.fetchPointers(true)
109+
go m.fetchPointersFromDHT()
109110
case <-peers.C:
110111
m.Add(1)
111-
go m.fetchPointers(false)
112+
go m.fetchPointersFromPushNodes()
112113
}
113114
}
114115
}
115116

116117
// RunOnce - used to fetch messages only once
117118
func (m *MessageRetriever) RunOnce() {
118119
m.Add(1)
119-
go m.fetchPointers(true)
120+
go m.fetchPointersFromDHT()
120121
m.Add(1)
121-
go m.fetchPointers(false)
122+
go m.fetchPointersFromPushNodes()
122123
}
123124

124-
func (m *MessageRetriever) fetchPointers(useDHT bool) {
125+
func (m *MessageRetriever) fetchPointersFromDHT() {
125126
ctx, cancel := context.WithCancel(context.Background())
126127
defer cancel()
127-
wg := new(sync.WaitGroup)
128-
downloaded := 0
129128
mh, _ := multihash.FromB58String(m.node.Identity.Pretty())
130129
peerOut := make(chan ps.PeerInfo)
131130
go func(c chan ps.PeerInfo) {
132-
pwg := new(sync.WaitGroup)
133-
pwg.Add(1)
134-
go func(c chan ps.PeerInfo) {
135-
out := m.getPointersDataPeers()
136-
for p := range out {
137-
c <- p
138-
}
139-
pwg.Done()
140-
}(c)
141-
if useDHT {
142-
pwg.Add(1)
143-
go func(c chan ps.PeerInfo) {
144-
iout := ipfs.FindPointersAsync(m.routing, ctx, mh, m.prefixLen)
145-
for p := range iout {
146-
c <- p
147-
}
148-
pwg.Done()
149-
}(c)
131+
iout := ipfs.FindPointersAsync(m.routing, ctx, mh, m.prefixLen)
132+
for p := range iout {
133+
c <- p
134+
}
135+
close(c)
136+
137+
}(peerOut)
138+
139+
m.downloadMessages(peerOut)
140+
}
141+
142+
func (m *MessageRetriever) fetchPointersFromPushNodes() {
143+
peerOut := make(chan ps.PeerInfo)
144+
go func(c chan ps.PeerInfo) {
145+
out := m.getPointersDataPeers()
146+
for p := range out {
147+
c <- p
150148
}
151-
pwg.Wait()
152149
close(c)
150+
153151
}(peerOut)
152+
m.downloadMessages(peerOut)
153+
}
154+
155+
func (m *MessageRetriever) downloadMessages(peerOut chan ps.PeerInfo) {
156+
wg := new(sync.WaitGroup)
157+
downloaded := 0
154158

155159
inFlight := make(map[string]bool)
156160
// Iterate over the pointers, adding 1 to the waitgroup for each pointer found
@@ -239,7 +243,7 @@ func (m *MessageRetriever) fetchIPFS(pid peer.ID, n *core.IpfsNode, addr ma.Mult
239243
var err error
240244

241245
go func() {
242-
ciphertext, err = ipfs.Cat(n, addr.String(), time.Minute*5)
246+
ciphertext, err = ipfs.Cat(n, addr.String(), time.Second*10)
243247
c <- struct{}{}
244248
}()
245249

net/service/messagesender.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ func (ms *messageSender) prep() error {
111111
if ms.s != nil {
112112
return nil
113113
}
114-
115-
nstr, err := ms.service.host.NewStream(ms.service.ctx, ms.p, ipfs.IPFSProtocolAppMainnetOne)
114+
ctx, cancel := context.WithTimeout(ms.service.ctx, 3*time.Second)
115+
defer cancel()
116+
nstr, err := ms.service.host.NewStream(ctx, ms.p, ipfs.IPFSProtocolAppMainnetOne)
116117
if err != nil {
117118
return err
118119
}

repo/listing.go

+12
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ func UpdateListing(r []byte, isTestnet bool, dstore *Datastore, repoPath string)
185185
if err != nil {
186186
return Listing{}, err
187187
}
188+
skus := ld.Item.Skus
189+
for _, sku := range skus {
190+
if sku.BigSurcharge == "" {
191+
sku.BigSurcharge = "0"
192+
}
193+
if sku.BigQuantity == "" {
194+
sku.BigQuantity = "0"
195+
}
196+
}
197+
198+
ld.Item.Skus = skus
199+
188200
slug := ld.Slug
189201
exists, err := listingExists(slug, repoPath, isTestnet)
190202
if err != nil {

wallet/listeners/transaction_listener.go

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ func (l *TransactionListener) cleanupOrderState(isSale bool, contract *pb.Ricard
9090
}
9191

9292
func (l *TransactionListener) OnTransactionReceived(cb wallet.TransactionCallback) {
93-
log.Info("Transaction received", cb.Txid, cb.Height)
94-
9593
l.Lock()
9694
defer l.Unlock()
9795
for _, output := range cb.Outputs {

0 commit comments

Comments
 (0)