relay and client launcher started

This commit is contained in:
l0k18
2023-06-19 17:07:54 +01:00
parent b4810106ce
commit 55f806c9f4
9 changed files with 96 additions and 83 deletions

View File

@@ -0,0 +1,18 @@
package client
import (
"github.com/spf13/cobra"
)
func Init(c *cobra.Command) {
c.AddCommand(clientCommand)
}
var clientCommand = &cobra.Command{
Use: "client",
Short: "run a client",
Long: "Runs indra as a client, providing a wireguard tunnel and socks5 " +
"proxy as connectivity options",
Run: func(cmd *cobra.Command, args []string) {
},
}

View File

@@ -1,68 +0,0 @@
package main
//
// import (
// "github.com/spf13/cobra"
// "github.com/spf13/viper"
//
// "github.com/indra-labs/indra"
// "github.com/indra-labs/indra/pkg/crypto/key/prv"
// "github.com/indra-labs/indra/pkg/crypto/key/pub"
// "github.com/indra-labs/indra/pkg/interrupt"
// log2 "github.com/indra-labs/indra/pkg/proc/log"
// "github.com/indra-labs/indra/pkg/relay"
// "github.com/indra-labs/indra/pkg/relay/transport"
// "github.com/indra-labs/indra/pkg/util/slice"
// )
//
// var (
// eng *relay.Engine
// engineP2P []string
// engineRPC []string
// )
//
// func init() {
// pf := relayCmd.PersistentFlags()
// pf.StringSliceVarP(&engineP2P, "engineP2P-relay", "P",
// []string{"127.0.0.1:8337", "::1:8337"},
// "address/ports for IPv4 and v6 listeners")
// pf.StringSliceVarP(&engineRPC, "relay-control", "r",
// []string{"127.0.0.1:8339", "::1:8339"},
// "address/ports for IPv4 and v6 listeners")
// viper.BindPFlag("engineP2P-relay", seedCommand.PersistentFlags().Lookup("engineP2P-relay"))
// viper.BindPFlag("relay-control", seedCommand.PersistentFlags().Lookup(
// "relay-control"))
// rootCmd.AddCommand(relayCmd)
// }
//
// var relayCmd = &cobra.Command{
// Use: "relay",
// Short: "Runs a relay server.",
// Long: `Runs a server that can be controlled with RPC and CLI interfaces.`,
// Run: func(cmd *cobra.Command, args []string) {
//
// log2.SetLogLevel(log2.Debug)
//
// log.I.Ln("-- ", log2.App, "("+viper.GetString(""+
// "network")+") -",
// indra.SemVer, "- Network Freedom. --")
//
// var e error
// var idPrv *prv.HiddenService
// if idPrv, e = prv.GenerateKey(); check(e) {
// return
// }
// idPub := pub.Derive(idPrv)
// nTotal := 5
// tpt := transport.NewSim(nTotal)
// addr := slice.GenerateRandomAddrPortIPv4()
// nod, _ := relay.NewNode(addr, idPub, idPrv, tpt, 50000, true)
// eng, e = relay.NewEngine(tpt, idPrv, nod, nil, 5)
// interrupt.AddHandler(func() { eng.Q() })
// log.D.Ln("starting up server")
// eng.Start()
// eng.Wait()
// log.I.Ln("fin")
// return
// },
// }

17
cmd/indra/relay/relay.go Normal file
View File

@@ -0,0 +1,17 @@
package relay
import (
"github.com/spf13/cobra"
)
func Init(c *cobra.Command) {
c.AddCommand(relayCommand)
}
var relayCommand = &cobra.Command{
Use: "relay",
Short: "run a relay",
Long: "Runs indra as a full relay, with optional client",
Run: func(cmd *cobra.Command, args []string) {
},
}

View File

@@ -3,6 +3,8 @@ package main
import (
"errors"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/cmd/indra/client"
"github.com/indra-labs/indra/cmd/indra/relay"
"github.com/indra-labs/indra/cmd/indra/seed"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/spf13/cobra"
@@ -13,7 +15,7 @@ import (
var indraTxt = `indra (` + indra.SemVer + `) - Network Freedom.
indra is a lightning powered, distributed virtual private network for anonymising traffic on decentralised protocol networks.
indra is a lightning powered, distributed virtual private network that protects you from metadata collection and enables novel service models.
`
var (
@@ -55,6 +57,8 @@ func init() {
viper.BindPFlag("data-dir", rootCmd.PersistentFlags().Lookup("data-dir"))
viper.BindPFlag("network", rootCmd.PersistentFlags().Lookup("network"))
relay.Init(rootCmd)
client.Init(rootCmd)
seed.Init(rootCmd)
}

View File

@@ -14,7 +14,7 @@ func init() {
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version number",
Long: `All software has versions. This is Hugo's`,
Long: `All software has versions. This is mine. Semver formatted.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(indra.SemVer)
},

View File

@@ -1,8 +1,12 @@
package ads
import (
"errors"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/engine/node"
"github.com/indra-labs/indra/pkg/engine/payments"
"github.com/indra-labs/indra/pkg/engine/services"
"github.com/indra-labs/indra/pkg/onions/adaddress"
"github.com/indra-labs/indra/pkg/onions/adload"
"github.com/indra-labs/indra/pkg/onions/adpeer"
@@ -11,6 +15,7 @@ import (
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/multi"
"github.com/multiformats/go-multiaddr"
"net/netip"
"time"
)
@@ -22,10 +27,10 @@ var (
const DefaultAdExpiry = time.Hour * 24 * 7 // one week
type NodeAds struct {
Peer adpeer.Ad
Address adaddress.Ad
Services adservices.Ad
Load adload.Ad
Peer *adpeer.Ad
Address *adaddress.Ad
Services *adservices.Ad
Load *adload.Ad
}
func GetMultiaddr(n *node.Node) (ma multiaddr.Multiaddr, e error) {
@@ -50,7 +55,7 @@ func GenerateAds(n *node.Node, load byte) (na *NodeAds, e error) {
return
}
na = &NodeAds{
Peer: adpeer.Ad{
Peer: &adpeer.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
@@ -58,7 +63,7 @@ func GenerateAds(n *node.Node, load byte) (na *NodeAds, e error) {
},
RelayRate: n.RelayRate,
},
Address: adaddress.Ad{
Address: &adaddress.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
@@ -66,7 +71,7 @@ func GenerateAds(n *node.Node, load byte) (na *NodeAds, e error) {
},
Addr: ma,
},
Services: adservices.Ad{
Services: &adservices.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
@@ -74,7 +79,7 @@ func GenerateAds(n *node.Node, load byte) (na *NodeAds, e error) {
},
Services: svcs,
},
Load: adload.Ad{
Load: &adload.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
@@ -85,3 +90,39 @@ func GenerateAds(n *node.Node, load byte) (na *NodeAds, e error) {
}
return
}
const ErrNilNodeAds = "cannot process nil NodeAds"
func NodeFromAds(a *NodeAds) (n *node.Node, e error) {
if a == nil ||
a.Services == nil || a.Load == nil ||
a.Address == nil || a.Peer == nil {
return n, errors.New(ErrNilNodeAds)
}
var ap netip.AddrPort
if ap, e = multi.AddrToAddrPort(a.Address.Addr); fails(e) {
return
}
var svcs services.Services
for i := range a.Services.Services {
svcs = append(svcs, &services.Service{
Port: a.Services.Services[i].Port,
RelayRate: a.Services.Services[i].RelayRate,
Transport: nil, // todo: wen making?
})
}
n = &node.Node{
ID: nonce.NewID(),
AddrPort: &ap,
Identity: &crypto.Keys{
Pub: a.Address.Key,
Bytes: a.Address.Key.ToBytes(),
},
RelayRate: a.Peer.RelayRate,
Services: svcs,
Load: a.Load.Load,
PayChan: make(payments.PayChan, node.PaymentChanBuffers), // todo: other end stuff
Transport: nil, // this is populated when we dial it.
}
return
}

View File

@@ -34,9 +34,9 @@ type (
Engine struct {
ctx context.Context
cancel func()
Responses *responses.Pending
manager *sess.Manager
NodeAds *ads.NodeAds
Responses *responses.Pending
manager *sess.Manager
NodeAds *ads.NodeAds
Listener *transport.Listener
PubSub *pubsub.PubSub
topic *pubsub.Topic

View File

@@ -29,8 +29,9 @@ type Node struct {
sync.Mutex
AddrPort *netip.AddrPort
Identity *crypto.Keys
RelayRate uint32 // Base relay price mSAT/Mb.
RelayRate uint32 // Base relay price mSAT/Mb.
Services services.Services // Services offered by this peer.
Load byte
payments.PayChan
Transport tpt.Transport
}

View File

@@ -1,9 +1,9 @@
package p2p
import (
"github.com/dgraph-io/badger/v3"
"github.com/indra-labs/indra/pkg/cfg"
"github.com/indra-labs/indra/pkg/storage"
"github.com/dgraph-io/badger/v3"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/multiformats/go-multiaddr"
"github.com/spf13/viper"