Merge remote-tracking branch 'origin/protocol'
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="go test git-indra.lan/indra-labs/indra/pkg (1)" type="GoTestRunConfiguration" factoryName="Go Test" singleton="false">
|
||||
<module name="indra" />
|
||||
<working_directory value="$PROJECT_DIR$/pkg" />
|
||||
<go_parameters value="-v ./... -tags local -ldflags "-X indra.CI=true" -gcflags "all=-trimpath=$ContentRoot$"" />
|
||||
<root_directory value="$PROJECT_DIR$" />
|
||||
<kind value="DIRECTORY" />
|
||||
<package value="git-indra.lan/indra-labs/indra/pkg/engine" />
|
||||
<directory value="$PROJECT_DIR$/pkg" />
|
||||
<filePath value="$PROJECT_DIR$" />
|
||||
<framework value="gotest" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,5 +1,5 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="go test local" type="GoTestRunConfiguration" factoryName="Go Test">
|
||||
<configuration default="false" name="go test local loki" type="GoTestRunConfiguration" factoryName="Go Test">
|
||||
<module name="indra" />
|
||||
<working_directory value="$PROJECT_DIR$/pkg" />
|
||||
<go_parameters value="-v ./... -tags local -gcflags "all=-trimpath=$PROJECT_DIR$"" />
|
||||
@@ -1,14 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="go test onions" type="GoTestRunConfiguration" factoryName="Go Test" singleton="true">
|
||||
<module name="indra" />
|
||||
<working_directory value="$PROJECT_DIR$/pkg/onions" />
|
||||
<go_parameters value="-v ./... -tags local -gcflags "all=-trimpath=$ContentRoot$"" />
|
||||
<root_directory value="$PROJECT_DIR$" />
|
||||
<kind value="DIRECTORY" />
|
||||
<package value="git-indra.lan/indra-labs/indra/pkg/onions" />
|
||||
<directory value="$PROJECT_DIR$/pkg/onions" />
|
||||
<filePath value="$PROJECT_DIR$" />
|
||||
<framework value="gotest" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -77,19 +77,9 @@ func New(p Params) (ng *Engine, e error) {
|
||||
Pause: qu.T(),
|
||||
}
|
||||
if p.Listener != nil && p.Listener.Host != nil {
|
||||
if ng.PubSub, e = pubsub.NewGossipSub(ctx, p.Listener.Host); fails(e) {
|
||||
cancel()
|
||||
if ng.PubSub, ng.topic, ng.sub, e = SetupGossip(ctx, p.Listener.Host, cancel); fails(e) {
|
||||
return
|
||||
}
|
||||
if ng.topic, e = ng.PubSub.Join(PubSubTopic); fails(e) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
if ng.sub, e = ng.topic.Subscribe(); fails(e) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
log.T.Ln("subscribed to", PubSubTopic, "topic on gossip network")
|
||||
}
|
||||
if ng.NodeAds, e = ads.GenerateAds(p.Node, 25); fails(e) {
|
||||
cancel()
|
||||
@@ -105,6 +95,32 @@ func New(p Params) (ng *Engine, e error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown triggers the shutdown of the client and the Cleanup before
|
||||
// finishing.
|
||||
func (ng *Engine) Shutdown() {
|
||||
log.T.Ln("shutting down", ng.Mgr().GetLocalNodeAddress().String())
|
||||
if ng.ShuttingDown.Load() {
|
||||
return
|
||||
}
|
||||
ng.ShuttingDown.Store(true)
|
||||
ng.Cleanup()
|
||||
ng.cancel()
|
||||
}
|
||||
|
||||
// Start a single thread of the Engine.
|
||||
func (ng *Engine) Start() {
|
||||
log.T.Ln("starting engine")
|
||||
if ng.sub != nil {
|
||||
log.T.Ln("starting gossip handling")
|
||||
ng.RunAdHandler(ng.HandleAd)
|
||||
}
|
||||
for {
|
||||
if ng.Handler() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup closes and flushes any resources the client opened that require sync
|
||||
// in order to reopen correctly.
|
||||
func (ng *Engine) Cleanup() {
|
||||
@@ -205,29 +221,3 @@ func (ng *Engine) WaitForShutdown() <-chan struct{} { return ng.ctx.Done() }
|
||||
func (ng *Engine) Mgr() *sess.Manager { return ng.manager }
|
||||
func (ng *Engine) Pending() *responses.Pending { return ng.Responses }
|
||||
func (ng *Engine) SetLoad(load byte) { ng.Load.Store(uint32(load)) }
|
||||
|
||||
// Shutdown triggers the shutdown of the client and the Cleanup before
|
||||
// finishing.
|
||||
func (ng *Engine) Shutdown() {
|
||||
log.T.Ln("shutting down", ng.Mgr().GetLocalNodeAddress().String())
|
||||
if ng.ShuttingDown.Load() {
|
||||
return
|
||||
}
|
||||
ng.ShuttingDown.Store(true)
|
||||
ng.Cleanup()
|
||||
ng.cancel()
|
||||
}
|
||||
|
||||
// Start a single thread of the Engine.
|
||||
func (ng *Engine) Start() {
|
||||
log.T.Ln("starting engine")
|
||||
if ng.sub != nil {
|
||||
log.T.Ln("starting gossip handling")
|
||||
ng.RunAdHandler(ng.HandleAd)
|
||||
}
|
||||
for {
|
||||
if ng.Handler() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/indra-labs/indra/pkg/ad"
|
||||
"github.com/indra-labs/indra/pkg/onions/adload"
|
||||
"github.com/indra-labs/indra/pkg/util/slice"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"reflect"
|
||||
|
||||
@@ -19,12 +20,31 @@ import (
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
)
|
||||
|
||||
func SetupGossip(ctx context.Context, host host.Host,
|
||||
cancel func()) (PubSub *pubsub.PubSub, topic *pubsub.Topic,
|
||||
sub *pubsub.Subscription, e error) {
|
||||
|
||||
if PubSub, e = pubsub.NewGossipSub(ctx, host); fails(e) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
if topic, e = PubSub.Join(PubSubTopic); fails(e) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
if sub, e = topic.Subscribe(); fails(e) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
log.T.Ln("subscribed to", PubSubTopic, "topic on gossip network")
|
||||
return
|
||||
}
|
||||
|
||||
func (ng *Engine) SendAd(a slice.Bytes) (e error) {
|
||||
return ng.topic.Publish(ng.ctx, a)
|
||||
}
|
||||
|
||||
func (ng *Engine) RunAdHandler(handler func(p *pubsub.Message,
|
||||
ctx context.Context) (e error)) {
|
||||
func (ng *Engine) RunAdHandler(handler func(p *pubsub.Message) (e error)) {
|
||||
|
||||
// Since the frequency of updates should be around 1 hour we run here only
|
||||
// one thread here. Relays indicate their loading as part of the response
|
||||
@@ -38,7 +58,7 @@ func (ng *Engine) RunAdHandler(handler func(p *pubsub.Message,
|
||||
continue
|
||||
}
|
||||
log.D.Ln("received message from gossip network")
|
||||
if e = handler(m, ng.ctx); fails(e) {
|
||||
if e = handler(m); fails(e) {
|
||||
continue
|
||||
}
|
||||
select {
|
||||
@@ -54,7 +74,7 @@ func (ng *Engine) RunAdHandler(handler func(p *pubsub.Message,
|
||||
|
||||
const ErrWrongTypeDecode = "magic '%s' but type is '%s'"
|
||||
|
||||
func (ng *Engine) HandleAd(p *pubsub.Message, ctx context.Context) (e error) {
|
||||
func (ng *Engine) HandleAd(p *pubsub.Message) (e error) {
|
||||
if len(p.Data) < 1 {
|
||||
log.E.Ln("received slice of no length")
|
||||
return
|
||||
|
||||
@@ -21,8 +21,8 @@ func InitFlags(cmd *cobra.Command) {
|
||||
|
||||
cmd.PersistentFlags().StringSliceVarP(&listeners, listenFlag, "",
|
||||
[]string{
|
||||
"/ip4/127.0.0.1/tcp/8337",
|
||||
"/ip6/::1/tcp/8337",
|
||||
"/ip4/0.0.0.0/tcp/8337",
|
||||
"/ip6/::/tcp/8337",
|
||||
},
|
||||
"binds to an interface",
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ package introducer
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
"sync"
|
||||
|
||||
@@ -47,13 +48,14 @@ func Bootstrap(ctx context.Context, host host.Host, seeds []multiaddr.Multiaddr)
|
||||
c = ctx
|
||||
h = host
|
||||
|
||||
log.I.Ln("using seeds:")
|
||||
|
||||
o := "using seeds:\n\n"
|
||||
|
||||
var bootstrapPeer *peer.AddrInfo
|
||||
|
||||
for _, seed := range seeds {
|
||||
|
||||
log.I.Ln("-", seed.String())
|
||||
o+=fmt.Sprintln("-", seed.String())
|
||||
|
||||
if bootstrapPeer, err = peer.AddrInfoFromP2pAddr(seed); check(err) {
|
||||
return
|
||||
@@ -67,6 +69,8 @@ func Bootstrap(ctx context.Context, host host.Host, seeds []multiaddr.Multiaddr)
|
||||
bootstrapPeers = append(bootstrapPeers, *bootstrapPeer)
|
||||
}
|
||||
|
||||
log.I.Ln(o)
|
||||
|
||||
var options = []dht.Option{
|
||||
dht.Mode(dht.ModeServer),
|
||||
dht.ProtocolPrefix(protocolPrefix),
|
||||
|
||||
@@ -43,11 +43,11 @@ func HostStatus(ctx context.Context, host host.Host) {
|
||||
select {
|
||||
case <-time.After(hostStatusInterval):
|
||||
|
||||
log.I.Ln()
|
||||
log.I.Ln("---- host status ----")
|
||||
log.I.Ln("-- peers:", len(host.Network().Peers()))
|
||||
log.I.Ln("-- connections:", len(host.Network().Conns()))
|
||||
log.I.Ln("---- ---- ------ ----")
|
||||
log.I.Ln(`
|
||||
---- host status ----
|
||||
-- peers:`, len(host.Network().Peers()),`
|
||||
-- connections:`, len(host.Network().Conns()),`
|
||||
`)
|
||||
|
||||
case <-ctx.Done():
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package storage
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -83,35 +83,35 @@ func configureKey() {
|
||||
return
|
||||
}
|
||||
|
||||
log.W.Ln("")
|
||||
log.W.Ln("--------------------------------------------------------")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- WARNING: The following key will be used to store")
|
||||
log.W.Ln("-- your database securely, please ensure that you make")
|
||||
log.W.Ln("-- a copy and store it in a secure place before using")
|
||||
log.W.Ln("-- this software in a production environment.")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- Failure to store this key properly will result in")
|
||||
log.W.Ln("-- no longer being able to decrypt this database.")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- It is recommended to use the following to generate")
|
||||
log.W.Ln("-- your key:")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- indra seed keygen")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- OR")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- indra seed keygen --keyfile=/path/to/keyfile")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-- YOU HAVE BEEN WARNED!")
|
||||
log.W.Ln("--")
|
||||
log.W.Ln("-------------------------------------------------------")
|
||||
log.W.Ln("-- KEY:", key.Encode(), "--")
|
||||
log.W.Ln("-------------------------------------------------------")
|
||||
log.W.Ln("")
|
||||
log.W.Ln(`
|
||||
--------------------------------------------------------
|
||||
--
|
||||
-- WARNING: The following key will be used to store
|
||||
-- your database securely, please ensure that you make
|
||||
-- a copy and store it in a secure place before using
|
||||
-- this software in a production environment.
|
||||
--
|
||||
--
|
||||
-- Failure to store this key properly will result in
|
||||
-- no longer being able to decrypt this database.
|
||||
--
|
||||
--
|
||||
-- It is recommended to use the following to generate
|
||||
-- your key:
|
||||
--
|
||||
-- indra seed keygen
|
||||
--
|
||||
-- OR
|
||||
--
|
||||
-- indra seed keygen --keyfile=/path/to/keyfile
|
||||
--
|
||||
--
|
||||
-- YOU HAVE BEEN WARNED!
|
||||
--
|
||||
-------------------------------------------------------
|
||||
-- KEY:`, key.Encode(), `--
|
||||
-------------------------------------------------------
|
||||
`)
|
||||
|
||||
newKeyGenerated = true
|
||||
|
||||
@@ -123,11 +123,11 @@ func configureDirPath() {
|
||||
var err error
|
||||
|
||||
if viper.GetString(storeFilePathFlag) == "" {
|
||||
viper.Set(storeFilePathFlag, viper.GetString("data-dir")+"/"+fileName)
|
||||
viper.Set(storeFilePathFlag, filepath.Join(viper.GetString("data-dir"), fileName))
|
||||
}
|
||||
|
||||
err = os.MkdirAll(
|
||||
strings.TrimSuffix(viper.GetString(storeFilePathFlag), "/"+fileName),
|
||||
filepath.Dir(storeFilePathFlag),
|
||||
0755,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"github.com/indra-labs/indra/pkg/util/appdata"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -38,7 +40,7 @@ func InitFlags(cmd *cobra.Command) {
|
||||
viper.BindPFlag(storeKeyFileFlag, cmd.PersistentFlags().Lookup(storeKeyFileFlag))
|
||||
|
||||
cmd.PersistentFlags().StringVarP(&storeFilePath, storeFilePathFlag, "",
|
||||
"",
|
||||
filepath.Join(appdata.Dir("indra", false), "indra.db"),
|
||||
"the path of the database (default is <data-dir>/indra.db)",
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"github.com/indra-labs/indra/pkg/rpc"
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
"github.com/indra-labs/indra/pkg/rpc"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"sync"
|
||||
|
||||
Reference in New Issue
Block a user