This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
/
openbazaard.go
115 lines (107 loc) · 3.27 KB
/
openbazaard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"os"
"os/signal"
"path/filepath"
"github.com/OpenBazaar/openbazaar-go/cmd"
"github.com/OpenBazaar/openbazaar-go/core"
"github.com/ipfs/go-ipfs/repo/fsrepo"
"github.com/jessevdk/go-flags"
"github.com/op/go-logging"
)
var log = logging.MustGetLogger("main")
type Opts struct {
Version bool `short:"v" long:"version" description:"Print the version number and exit"`
}
var opts Opts
var parser = flags.NewParser(&opts, flags.Default)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
log.Noticef("Received %s\n", sig)
log.Info("OpenBazaar Server shutting down...")
if core.Node != nil {
if core.Node.MessageRetriever != nil {
core.Node.RecordAgingNotifier.Stop()
core.Node.InboundMsgScanner.Stop()
close(core.Node.MessageRetriever.DoneChan)
core.Node.MessageRetriever.Wait()
}
core.OfflineMessageWaitGroup.Wait()
core.Node.PublishLock.Lock()
core.Node.Datastore.Close()
repoLockFile := filepath.Join(core.Node.RepoPath, fsrepo.LockFile)
os.Remove(repoLockFile)
core.Node.Multiwallet.Close()
core.Node.IpfsNode.Close()
}
os.Exit(1)
}
}()
_, err := parser.AddCommand("gencerts",
"Generate certificates",
"Generate self-signed certificates",
&cmd.GenerateCertificates{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("init",
"initialize a new repo and exit",
"Initializes a new repo without starting the server",
&cmd.Init{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("status",
"get the repo status",
"Returns the status of the repo ― Uninitialized, Encrypted, Decrypted. Also returns whether Tor is available.",
&cmd.Status{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("setapicreds",
"set API credentials",
"The API password field in the config file takes a SHA256 hash of the password. This command will generate the hash for you and save it to the config file.",
&cmd.SetAPICreds{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("start",
"start the OpenBazaar-Server",
"The start command starts the OpenBazaar-Server",
&cmd.Start{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("encryptdatabase",
"encrypt your database",
"This command encrypts the database containing your bitcoin private keys, identity key, and contracts",
&cmd.EncryptDatabase{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("decryptdatabase",
"decrypt your database",
"This command decrypts the database containing your bitcoin private keys, identity key, and contracts.\n [Warning] doing so may put your bitcoins at risk.",
&cmd.DecryptDatabase{})
if err != nil {
log.Error(err)
}
_, err = parser.AddCommand("restore",
"restore user data",
"This command will attempt to restore user data (profile, listings, ratings, etc) by downloading them from the network. This will only work if the IPNS mapping is still available in the DHT. Optionally it will take a mnemonic seed to restore from.",
&cmd.Restore{})
if err != nil {
log.Error(err)
}
if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-v") {
fmt.Println(core.VERSION)
return
}
if _, err := parser.Parse(); err != nil {
os.Exit(1)
}
}