Skip to content

Commit

Permalink
Upgraded to go-orbit-db 1.17.1, fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mrusme committed May 6, 2022
1 parent 5ef5fe5 commit f142aad
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 47 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ KNOWN LIMITATIONS
can alter its data. Since its using a standard _docstore_, PUT and DELETE
events can alter existing data. This issue will be solved in the future by
customizing the store to ignore these types of events.
- Superhighway84 is always behind recent IPFS and also OrbitDB versions, mainly
because Berty, the go-orbit-db maintainers, aren't exactly super helpful
and welcoming in regard of the usage of their library. Not only do they
Expand All @@ -254,6 +255,7 @@ KNOWN LIMITATIONS
now, so Superhighway84 is basically stuck with it.
If you happen to know your way around IPFS and maybe even go-orbit-db, and
would like to support this project, please get in touch!
- If you have a newer IPFS version installed than the one used by
Superhighway84, please make sure to **not upgrade** the IPFS_REPO that
Superhighway84 is using. Otherwise you will get an error when starting
Expand All @@ -265,6 +267,19 @@ KNOWN LIMITATIONS
https://github.com/mrusme/superhighway84/issues/42#issuecomment-1100582472
- If you encounter the following issue your IPFS repo version might be older
than what Superhighway84 is using:
> panic: ipfs repo needs migration
In this case you might want to follow the IPFS migration guide here:
https://github.com/ipfs/fs-repo-migrations/blob/master/run.md
Alternatively use the same IPFS version as used by Superhighway84 to
initialize a dedicated Superhighway84 repository. Please refer to the
INSTALLATION part for how to do so.
CREDITS
Expand Down
40 changes: 25 additions & 15 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"sort"
"sync"
"time"

orbitdb "berty.tech/go-orbit-db"
"berty.tech/go-orbit-db/accesscontroller"
Expand Down Expand Up @@ -43,7 +44,12 @@ type Database struct {
func (db *Database) init() (error) {
var err error

db.OrbitDB, err = orbitdb.NewOrbitDB(db.ctx, db.IPFSCoreAPI, &orbitdb.NewOrbitDBOptions{
// ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), 600 * time.Second)
defer cancel()

db.Logger.Debug("initializing NewOrbitDB ...")
db.OrbitDB, err = orbitdb.NewOrbitDB(ctx, db.IPFSCoreAPI, &orbitdb.NewOrbitDBOptions{
Directory: &db.CachePath,
Logger: db.Logger,
})
Expand All @@ -70,15 +76,18 @@ func (db *Database) init() (error) {
// db.URI = addr.String()

storetype := "docstore"
db.Store, err = db.OrbitDB.Docs(db.ctx, db.ConnectionString, &orbitdb.CreateDBOptions{
db.Logger.Debug("initializing OrbitDB.Docs ...")
db.Store, err = db.OrbitDB.Docs(ctx, db.ConnectionString, &orbitdb.CreateDBOptions{
AccessController: ac,
StoreType: &storetype,
StoreSpecificOpts: documentstore.DefaultStoreOptsForMap("id"),
Timeout: time.Second * 600,
})
if err != nil {
return err
}

db.Logger.Debug("subscribing to EventBus ...")
db.Events, err = db.Store.EventBus().Subscribe(new(stores.EventReady))
return nil
}
Expand Down Expand Up @@ -136,15 +145,18 @@ func NewDatabase(
db.Cache = cch
db.Logger = logger

db.Logger.Debug("getting config root path ...")
defaultPath, err := config.PathRoot()
if err != nil {
return nil, err
}

db.Logger.Debug("setting up plugins ...")
if err := setupPlugins(defaultPath); err != nil {
return nil, err
}

db.Logger.Debug("creating IPFS node ...")
db.IPFSNode, db.IPFSCoreAPI, err = createNode(ctx, defaultPath)
if err != nil {
return nil, err
Expand All @@ -156,7 +168,18 @@ func NewDatabase(
func (db *Database) Connect(onReady func(address string)) (error) {
var err error

db.Logger.Info("connecting to peers ...")
// go func() {
err = db.connectToPeers()
if err != nil {
db.Logger.Error("failed to connect: %s", zap.Error(err))
} else {
db.Logger.Debug("connected to peer!")
}
// }()


db.Logger.Info("initializing database connection ...")
// if db.Init {
err = db.init()
if err != nil {
Expand All @@ -170,19 +193,6 @@ func (db *Database) Connect(onReady func(address string)) (error) {
// }
// }

// go func() {
err = db.connectToPeers()
if err != nil {
db.Logger.Error("failed to connect: %s", zap.Error(err))
} else {
db.Logger.Debug("connected to peer!")
}
// }()

// log.Println(db.Store.ReplicationStatus().GetBuffered())
// log.Println(db.Store.ReplicationStatus().GetQueued())
// log.Println(db.Store.ReplicationStatus().GetProgress())

db.Logger.Info("running ...")

go func() {
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/mrusme/superhighway84
go 1.17

require (
berty.tech/go-orbit-db v1.16.1
berty.tech/go-orbit-db v1.17.1
github.com/BurntSushi/toml v1.0.0
github.com/eliukblau/pixterm v1.3.1
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
github.com/go-playground/validator/v10 v10.10.1
github.com/google/uuid v1.3.0
github.com/ipfs/go-ipfs v0.11.0
github.com/ipfs/go-ipfs v0.12.2
github.com/ipfs/go-ipfs-config v0.18.0
github.com/ipfs/go-ipfs-files v0.0.9
github.com/ipfs/interface-go-ipfs-core v0.5.2
Expand All @@ -23,7 +23,7 @@ require (

require (
bazil.org/fuse v0.0.0-20200117225306-7b5117fecadc // indirect
berty.tech/go-ipfs-log v1.7.0 // indirect
berty.tech/go-ipfs-log v1.8.0 // indirect
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/Stebalien/go-bitfield v0.0.1 // indirect
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a // indirect
Expand Down Expand Up @@ -78,13 +78,13 @@ require (
github.com/ipfs/go-ds-leveldb v0.5.0 // indirect
github.com/ipfs/go-ds-measure v0.2.0 // indirect
github.com/ipfs/go-fetcher v1.6.1 // indirect
github.com/ipfs/go-filestore v0.1.0 // indirect
github.com/ipfs/go-filestore v1.1.0 // indirect
github.com/ipfs/go-fs-lock v0.0.7 // indirect
github.com/ipfs/go-graphsync v0.11.0 // indirect
github.com/ipfs/go-ipfs-blockstore v0.2.1 // indirect
github.com/ipfs/go-ipfs-blockstore v1.1.2 // indirect
github.com/ipfs/go-ipfs-chunker v0.0.5 // indirect
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
github.com/ipfs/go-ipfs-ds-help v0.1.1 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-exchange-interface v0.1.0 // indirect
github.com/ipfs/go-ipfs-exchange-offline v0.1.1 // indirect
github.com/ipfs/go-ipfs-keystore v0.0.2 // indirect
Expand All @@ -110,7 +110,7 @@ require (
github.com/ipfs/go-unixfs v0.3.1 // indirect
github.com/ipfs/go-unixfsnode v1.1.3 // indirect
github.com/ipfs/go-verifcid v0.0.1 // indirect
github.com/ipld/go-codec-dagpb v1.3.0 // indirect
github.com/ipld/go-codec-dagpb v1.3.2 // indirect
github.com/ipld/go-ipld-prime v0.14.2 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
Expand Down Expand Up @@ -226,15 +226,15 @@ require (
go.uber.org/fx v1.15.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211025112917-711f33c9992c // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
Expand Down
Loading

0 comments on commit f142aad

Please sign in to comment.