go modules and refactoring

This commit is contained in:
0xFugue 2023-01-14 20:31:59 +05:30
parent 6cf83ee0f5
commit 620962e001
6 changed files with 74 additions and 51 deletions

38
waku/common/commons.go Normal file
View File

@ -0,0 +1,38 @@
package common
import (
"time"
"math/rand"
"flag"
)
const StartPort = 60000
const Offset = 1000
const DnsDiscoveryUrl = "enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.waku.nodes.status.im"
const NameServer = "1.1.1.1"
type Config struct {
LogLevel string
Ofname string
ContentTopic string
Iat time.Duration
Duration time.Duration
}
func RandInt(min, max int) int {
return min + rand.Intn(max - min)
}
func ArgInit(conf *Config){
flag.DurationVar(&(*conf).Duration, "d", 1000*time.Second,
"Specify the duration (1s,2m,4h)")
flag.DurationVar(&(*conf).Iat, "i", 300*time.Millisecond,
"Specify the interarrival time in millisecs")
flag.StringVar(&(*conf).LogLevel, "l", "info",
"Specify the log level")
flag.StringVar(&(*conf).Ofname, "o", "lightpush.out",
"Specify the output file")
flag.StringVar(&(*conf).ContentTopic, "c", "6b6fd7006afdfe916f08b5d",
"Specify the content topic")
}

3
waku/common/go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/logos-co/wadoku/waku/common
go 1.18

View File

@ -6,6 +6,8 @@ import (
"fmt"
"net"
"bytes"
// "math/rand"
"strconv"
"encoding/binary"
"os"
"time"
@ -17,6 +19,7 @@ import (
"github.com/waku-org/go-waku/waku/v2/protocol"
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
"github.com/waku-org/go-waku/waku/v2/utils"
"github.com/logos-co/wadoku/waku/common"
//"crypto/rand"
//"encoding/hex"
//"github.com/ethereum/go-ethereum/crypto"
@ -26,33 +29,16 @@ import (
var log = logging.Logger("filter")
var pubSubTopic = protocol.DefaultPubsubTopic()
var conf = common.Config{}
const dnsDiscoveryUrl = "enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.waku.nodes.status.im"
const nameServer = "1.1.1.1" // your local dns provider might be blocking entr
//const dnsDiscoveryUrl = "enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.waku.nodes.status.im"
//const nameServer = "1.1.1.1" // your local dns provider might be blocking entr
type Config struct {
LogLevel string
Ofname string
ContentTopic string
Iat time.Duration
Duration time.Duration
}
var conf = Config{}
func init() {
// args
fmt.Println("Populating CLI params...")
flag.DurationVar(&conf.Duration, "d", 1000*time.Second,
"Specify the duration (1s,2m,4h)")
flag.DurationVar(&conf.Iat, "i", 300*time.Millisecond,
"Specify the interarrival time in millisecs")
flag.StringVar(&conf.LogLevel, "l", "info",
"Specify the log level")
flag.StringVar(&conf.Ofname, "o", "lightpush.out",
"Specify the output file")
flag.StringVar(&conf.ContentTopic, "c", "d608b04e6b6fd7006afdfe916f08b5d",
"Specify the content topic")
common.ArgInit(&conf)
}
func main() {
@ -66,8 +52,9 @@ func main() {
}
logging.SetAllLoggers(lvl)
tcpEndPoint := "0.0.0.0:" + strconv.Itoa(common.StartPort + common.RandInt(0, common.Offset))
// create the waku node
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:60000")
hostAddr, _ := net.ResolveTCPAddr("tcp", tcpEndPoint)
ctx := context.Background()
lightNode, err := node.New(ctx,
//node.WithWakuRelay(),
@ -80,8 +67,8 @@ func main() {
log.Info("CONFIG : ", conf)
// find the list of full node fleet peers
log.Info("attempting DNS discovery with: ", dnsDiscoveryUrl)
nodes, err := dnsdisc.RetrieveNodes(ctx, dnsDiscoveryUrl, dnsdisc.WithNameserver(nameServer))
log.Info("attempting DNS discovery with: ", common.DnsDiscoveryUrl)
nodes, err := dnsdisc.RetrieveNodes(ctx, common.DnsDiscoveryUrl, dnsdisc.WithNameserver(common.NameServer))
if err != nil {
panic(err.Error())
}

View File

@ -58,6 +58,7 @@ require (
github.com/libp2p/go-openssl v0.1.0 // indirect
github.com/libp2p/go-reuseport v0.2.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.0 // indirect
github.com/logos-co/wadoku/utils v0.0.1 // direct
github.com/lucas-clemente/quic-go v0.29.1 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
@ -121,3 +122,7 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)
replace github.com/logos-co/wadoku/waku/common => ../common
require github.com/logos-co/wadoku/waku/common v0.0.0

View File

@ -121,3 +121,8 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)
replace github.com/logos-co/wadoku/waku/common => ../common
require github.com/logos-co/wadoku/waku/common v0.0.0

View File

@ -6,6 +6,8 @@ import (
"fmt"
"net"
"bytes"
//"math/rand"
"strconv"
"encoding/binary"
"os"
"time"
@ -17,6 +19,8 @@ import (
"github.com/waku-org/go-waku/waku/v2/payload"
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/waku-org/go-waku/waku/v2/utils"
"github.com/logos-co/wadoku/waku/common"
//"crypto/rand"
//"encoding/hex"
//"github.com/ethereum/go-ethereum/crypto"
@ -27,36 +31,16 @@ import (
)
var log = logging.Logger("lightpush")
const NameServer = "1.1.1.1" // your local dns provider might be blocking entr
const DnsDiscoveryUrl = "enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.waku.nodes.status.im"
var seqNumber int32 = 0
type Config struct {
LogLevel string
Ofname string
ContentTopic string
Iat time.Duration
Duration time.Duration
}
var conf = Config{}
var conf = common.Config{}
func init() {
// args
fmt.Println("Populating CLI params...")
flag.DurationVar(&conf.Duration, "d", 1000*time.Second,
"Specify the duration (1s,2m,4h)")
flag.DurationVar(&conf.Iat, "i", 100*time.Millisecond,
"Specify the interarrival time in millisecs")
flag.StringVar(&conf.LogLevel, "l", "info",
"Specify the log level")
flag.StringVar(&conf.Ofname, "o", "lightpush.out",
"Specify the output file")
flag.StringVar(&conf.ContentTopic, "c", "d608b04e6b6fd7006afdfe916f08b5d",
"Specify the content topic")
common.ArgInit(&conf)
}
func main() {
flag.Parse()
@ -68,8 +52,9 @@ func main() {
}
logging.SetAllLoggers(lvl)
tcpEndPoint := "0.0.0.0:" + strconv.Itoa(common.StartPort + common.RandInt(0, common.Offset))
// create the waku node
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:60000")
hostAddr, _ := net.ResolveTCPAddr("tcp", tcpEndPoint)
ctx := context.Background()
lightNode, err := node.New(ctx,
node.WithWakuRelay(),
@ -83,8 +68,8 @@ func main() {
log.Info("config: ", conf)
// find the list of full node fleet peers
log.Info("attempting DNS discovery with: ", DnsDiscoveryUrl)
nodes, err := dnsdisc.RetrieveNodes(ctx, DnsDiscoveryUrl, dnsdisc.WithNameserver(NameServer))
log.Info("attempting DNS discovery with: ", common.DnsDiscoveryUrl)
nodes, err := dnsdisc.RetrieveNodes(ctx, common.DnsDiscoveryUrl, dnsdisc.WithNameserver(common.NameServer))
if err != nil {
panic(err.Error())
}
@ -123,7 +108,7 @@ func main() {
lightNode.Stop()
}
func writeLoop(ctx context.Context, conf *Config, wakuNode *node.WakuNode) {
func writeLoop(ctx context.Context, conf *common.Config, wakuNode *node.WakuNode) {
log.Info("STARTING THE WRITELOOP ", conf.ContentTopic)
f, err := os.OpenFile(conf.Ofname, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)