chore: rename pineconemanager to radio

Since pinecone already has a concept of a manager and also, this name is
a little more creative :D
This commit is contained in:
0x1a8510f2 2023-05-28 17:10:17 +01:00
parent 787a3f3065
commit ca058a7e14
Signed by: 0x1a8510f2
GPG Key ID: 1C692E355D76775D
8 changed files with 164 additions and 98 deletions

1
TODO Normal file
View File

@ -0,0 +1 @@
panel session extension to prevent getting logged out randomly?

View File

@ -17,8 +17,8 @@ import (
"syscall"
"time"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/pmanager"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/proto"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/radio"
)
//go:embed ui/dist/*
@ -52,22 +52,22 @@ func main() {
pineconeId := ed25519.PrivateKey(pineconeIdBytes)
// Get a struct for managing pinecone connections.
pm := pmanager.GetInstance()
pr := radio.GetInstance()
//
// Configure pinecone manager.
//
pm.SetPineconeIdentity(pineconeId)
pr.SetPineconeIdentity(pineconeId)
if c.logPinecone {
pm.SetLogger(log.Default())
pr.SetLogger(log.Default())
}
pm.SetInboundAddr(c.pineconeInboundTcpAddr)
pm.SetWebserverAddr(c.pineconeInboundWebAddr)
pm.SetWebserverDebugPath(c.pineconeDebugEndpoint)
pm.SetUseMulticast(c.pineconeUseMulticast)
pr.SetInboundAddr(c.pineconeInboundTcpAddr)
pr.SetWebserverAddr(c.pineconeInboundWebAddr)
pr.SetWebserverDebugPath(c.pineconeDebugEndpoint)
pr.SetUseMulticast(c.pineconeUseMulticast)
if c.pineconeStaticPeers != "" {
pm.SetStaticPeers(strings.Split(c.pineconeStaticPeers, ","))
pr.SetStaticPeers(strings.Split(c.pineconeStaticPeers, ","))
}
//
@ -90,7 +90,7 @@ func main() {
panic(err)
}
pm.SetWebserverHandlers([]pmanager.WebserverHandler{
pr.SetWebserverHandlers([]radio.WebserverHandler{
{
Path: "/X/",
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -161,7 +161,7 @@ func main() {
}
// Send the packet to client.
pm.Send(context.Background(), proto.Packet{
pr.Send(context.Background(), proto.Packet{
Peer: reqdata.Target,
Method: http.MethodPost,
Route: proto.ROUTE_REQUEST,
@ -228,12 +228,12 @@ func main() {
})
// Start pinecone.
go pm.Start()
go pr.Start()
// Start receiving messages.
// Background context is okay because the channel will be closed
// when the manager exits further down anyway.
recv := pm.RecvChan(context.Background())
recv := pr.RecvChan(context.Background())
mainloop:
for {
@ -289,7 +289,7 @@ mainloop:
os.Exit(1)
}()
pm.Stop()
pr.Stop()
os.Exit(0)
}

13
go.mod
View File

@ -6,6 +6,7 @@ require (
dev.l1qu1d.net/wraith-labs/wraith/wraith v0.0.0-20230412033239-573206620cac
github.com/cristalhq/jwt/v4 v4.0.2
github.com/fxamacker/cbor/v2 v2.4.0
github.com/gofiber/fiber/v2 v2.46.0
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
@ -14,14 +15,26 @@ require (
require (
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.34.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.47.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.9.0 // indirect

63
go.sum
View File

@ -2,6 +2,8 @@ dev.l1qu1d.net/wraith-labs/wraith/wraith v0.0.0-20230412033239-573206620cac h1:j
dev.l1qu1d.net/wraith-labs/wraith/wraith v0.0.0-20230412033239-573206620cac/go.mod h1:dGdo5ZSlCtXuTNFUuuVyyGymHCmLFFSuK1GmNGMOSV8=
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/cristalhq/jwt/v4 v4.0.2 h1:g/AD3h0VicDamtlM70GWGElp8kssQEv+5wYd7L9WOhU=
github.com/cristalhq/jwt/v4 v4.0.2/go.mod h1:HnYraSNKDRag1DZP92rYHyrjyQHnVEHPNqesmzs+miQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -29,6 +31,8 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gofiber/fiber/v2 v2.46.0 h1:wkkWotblsGVlLjXj2dpgKQAYHtXumsK/HyFugQM68Ns=
github.com/gofiber/fiber/v2 v2.46.0/go.mod h1:DNl0/c37WLe0g92U6lx1VMQuxGUQY5V7EIaVoEsUffc=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
@ -55,17 +59,24 @@ github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/onsi/ginkgo/v2 v2.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE=
github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM=
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U=
@ -74,55 +85,97 @@ github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8G
github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/quic-go v0.34.0 h1:OvOJ9LFjTySgwOTYUZmNoq0FzVicP8YujpV0kB7m2lU=
github.com/quic-go/quic-go v0.34.0/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c=
github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4=
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 h1:3xJIFvzUFbu4ls0BTBYcgbCGhA63eAOEMxIHugyXJqA=
golang.org/x/exp v0.0.0-20230519143937-03e91628a987/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -1,4 +1,4 @@
package pmanager
package radio
import (
"crypto/ed25519"
@ -107,49 +107,49 @@ func (c *config) snapshot() configSnapshot {
// Setters
//
func (pm *manager) SetPineconeIdentity(u ed25519.PrivateKey) {
func (pm *radio) SetPineconeIdentity(u ed25519.PrivateKey) {
defer pm.conf.autolock()()
pm.conf.pineconeIdentity = u
}
func (pm *manager) SetLogger(u *log.Logger) {
func (pm *radio) SetLogger(u *log.Logger) {
defer pm.conf.autolock()()
pm.conf.logger = u
}
func (pm *manager) SetInboundAddr(u string) {
func (pm *radio) SetInboundAddr(u string) {
defer pm.conf.autolock()()
pm.conf.inboundAddr = u
}
func (pm *manager) SetWebserverAddr(u string) {
func (pm *radio) SetWebserverAddr(u string) {
defer pm.conf.autolock()()
pm.conf.webserverAddr = u
}
func (pm *manager) SetWebserverDebugPath(u string) {
func (pm *radio) SetWebserverDebugPath(u string) {
defer pm.conf.autolock()()
pm.conf.webserverDebugPath = u
}
func (pm *manager) SetUseMulticast(u bool) {
func (pm *radio) SetUseMulticast(u bool) {
defer pm.conf.autolock()()
pm.conf.useMulticast = u
}
func (pm *manager) SetStaticPeers(u []string) {
func (pm *radio) SetStaticPeers(u []string) {
defer pm.conf.autolock()()
pm.conf.staticPeers = u
}
func (pm *manager) SetWebserverHandlers(u []WebserverHandler) {
func (pm *radio) SetWebserverHandlers(u []WebserverHandler) {
defer pm.conf.autolock()()
pm.conf.webserverHandlers = u
@ -159,49 +159,49 @@ func (pm *manager) SetWebserverHandlers(u []WebserverHandler) {
// Getters
//
func (pm *manager) GetPineconeIdentity() ed25519.PrivateKey {
func (pm *radio) GetPineconeIdentity() ed25519.PrivateKey {
defer pm.conf.autorlock()()
return pm.conf.pineconeIdentity
}
func (pm *manager) GetLogger() *log.Logger {
func (pm *radio) GetLogger() *log.Logger {
defer pm.conf.autorlock()()
return pm.conf.logger
}
func (pm *manager) GetInboundAddr() string {
func (pm *radio) GetInboundAddr() string {
defer pm.conf.autorlock()()
return pm.conf.inboundAddr
}
func (pm *manager) GetWebserverAddr() string {
func (pm *radio) GetWebserverAddr() string {
defer pm.conf.autorlock()()
return pm.conf.webserverAddr
}
func (pm *manager) GetWebserverDebugPath() string {
func (pm *radio) GetWebserverDebugPath() string {
defer pm.conf.autorlock()()
return pm.conf.webserverDebugPath
}
func (pm *manager) GetUseMulticast() bool {
func (pm *radio) GetUseMulticast() bool {
defer pm.conf.autorlock()()
return pm.conf.useMulticast
}
func (pm *manager) GetStaticPeers() []string {
func (pm *radio) GetStaticPeers() []string {
defer pm.conf.autorlock()()
return pm.conf.staticPeers
}
func (pm *manager) GetWebserverHandlers() []WebserverHandler {
func (pm *radio) GetWebserverHandlers() []WebserverHandler {
defer pm.conf.autorlock()()
return pm.conf.webserverHandlers

View File

@ -1,4 +1,4 @@
package pmanager
package radio
import (
"bytes"
@ -18,6 +18,7 @@ import (
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/misc"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/proto"
"github.com/gofiber/fiber/v2"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
pineconeConnections "github.com/matrix-org/pinecone/connections"
@ -26,7 +27,7 @@ import (
pineconeSessions "github.com/matrix-org/pinecone/sessions"
)
type Manager interface {
type Radio interface {
GetInboundAddr() string
GetLogger() *log.Logger
GetPineconeIdentity() ed25519.PrivateKey
@ -54,7 +55,7 @@ type Manager interface {
const PROTOCOL_NAME = "wraith-module-pinecomms"
type manager struct {
type radio struct {
// Once instances ensuring that each method is only executed once at a given time.
startOnce misc.CheckableOnce
stopOnce misc.CheckableOnce
@ -66,13 +67,13 @@ type manager struct {
txq chan proto.Packet
rxq chan proto.Packet
// A struct of config options for the manager with a lock to make it thread-safe.
// A struct of config options for the radio with a lock to make it thread-safe.
conf config
}
// Start the pinecone manager as configured. This blocks while the
// manager is running but can be started in a goroutine.
func (pm *manager) Start() {
// Start the pinecone radio as configured. This blocks while the
// radio is running but can be started in a goroutine.
func (pm *radio) Start() {
// Reset startOnce when this function exits.
defer func() {
pm.startOnce = misc.CheckableOnce{}
@ -81,8 +82,8 @@ func (pm *manager) Start() {
// Only execute this once at a time.
pm.startOnce.Do(func() {
// Init some internal communication channels.
managerInstance.reqExit = make(chan struct{})
managerInstance.ackExit = make(chan struct{})
radioInstance.reqExit = make(chan struct{})
radioInstance.ackExit = make(chan struct{})
// Grab a snapshot of the config (this ensures the
// config is never in an inconsistent state when values
@ -133,18 +134,16 @@ func (pm *manager) Start() {
pHTTP := pQUIC.Protocol(PROTOCOL_NAME).HTTP()
pHTTP.Mux().Handle("/", pMux)
app := fiber.New(fiber.Config{
DisableStartupMessage: true,
DisablePreParseMultipartForm: true,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 10 * time.Second,
})
// Pinecone HTTP server.
pineconeHttpServer := http.Server{
Addr: ":0",
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){},
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 60 * time.Second,
BaseContext: func(_ net.Listener) context.Context {
return ctx
},
Handler: pMux,
}
pineconeHttpServer := app.Server()
// Start pinecone HTTP server in goroutine.
wg.Add(1)
@ -317,7 +316,7 @@ func (pm *manager) Start() {
// Tear down pinecone HTTP server.
phttpShutdownTimeoutCtx, phttpShutdownTimeoutCtxCancel := context.WithTimeout(context.Background(), time.Second*2)
pineconeHttpServer.Shutdown(phttpShutdownTimeoutCtx)
pineconeHttpServer.ShutdownWithContext(phttpShutdownTimeoutCtx)
phttpShutdownTimeoutCtxCancel()
// Tear down pinecone components.
@ -337,21 +336,21 @@ func (pm *manager) Start() {
})
}
// Stop the pinecone manager.
func (pm *manager) Stop() {
// Stop the pinecone radio.
func (pm *radio) Stop() {
// Reset stopOnce when this function exits.
defer func(pm *manager) {
defer func(pm *radio) {
pm.stopOnce = misc.CheckableOnce{}
}(pm)
// Only execute this once at a time.
pm.stopOnce.Do(func() {
// Only actually do anything if the manager is running, otherwise
// Only actually do anything if the radio is running, otherwise
// we'll block forever because nothing would read from the channel.
//
// Theoretically the manager could exit after our check but before
// Theoretically the radio could exit after our check but before
// we write to the channel which causes a race and results in a
// deadlock. In practice this should be impossible as the manager
// deadlock. In practice this should be impossible as the radio
// can only exit when this function is called and only one of this
// function can run at a time. The guarantee could be made stronger
// with locks but this isn't really worth the added complexity.
@ -364,10 +363,10 @@ func (pm *manager) Stop() {
})
}
// Restart the pinecone manager. Equivalent to calling Stop() and Start().
func (pm *manager) Restart() {
// Restart the pinecone radio. Equivalent to calling Stop() and Start().
func (pm *radio) Restart() {
// Reset restartOnce when this function exits.
defer func(pm *manager) {
defer func(pm *radio) {
pm.restartOnce = misc.CheckableOnce{}
}(pm)
@ -379,12 +378,12 @@ func (pm *manager) Restart() {
}
// Send a given packet to a specific peer.
func (pm *manager) Send(ctx context.Context, p proto.Packet) error {
func (pm *radio) Send(ctx context.Context, p proto.Packet) error {
select {
case pm.txq <- p:
return nil
case <-pm.ackExit:
return fmt.Errorf("manager exited while trying to send packet")
return fmt.Errorf("radio exited while trying to send packet")
case <-ctx.Done():
return fmt.Errorf("context cancelled while trying to send packet (%e)", ctx.Err())
}
@ -392,19 +391,19 @@ func (pm *manager) Send(ctx context.Context, p proto.Packet) error {
// Receive incoming packets. Blocks until either a packet is received or
// the provided context expires.
func (pm *manager) Recv(ctx context.Context) (proto.Packet, error) {
func (pm *radio) Recv(ctx context.Context) (proto.Packet, error) {
select {
case p := <-pm.rxq:
return p, nil
case <-pm.ackExit:
return proto.Packet{}, fmt.Errorf("manager exited while trying to receive packet")
return proto.Packet{}, fmt.Errorf("radio exited while trying to receive packet")
case <-ctx.Done():
return proto.Packet{}, fmt.Errorf("context cancelled while trying to receive packet (%e)", ctx.Err())
}
}
// Receive incoming packets from a channel.
func (pm *manager) RecvChan(ctx context.Context) chan proto.Packet {
func (pm *radio) RecvChan(ctx context.Context) chan proto.Packet {
c := make(chan proto.Packet)
go func() {
defer func() {
@ -421,29 +420,29 @@ func (pm *manager) RecvChan(ctx context.Context) chan proto.Packet {
return c
}
// Check whether the pinecone manager is currently running.
func (pm *manager) IsRunning() bool {
// Check whether the pinecone radio is currently running.
func (pm *radio) IsRunning() bool {
return pm.startOnce.Doing()
}
var initonce sync.Once
var managerInstance *manager = nil
var radioInstance *radio = nil
// Get the instance of the pinecone manager. This instance is shared for
// Get the instance of the pinecone radio. This instance is shared for
// the entire program and successive calls return the existing instance.
func GetInstance() Manager {
// Create and initialise an instance of manager only once.
func GetInstance() Radio {
// Create and initialise an instance of radio only once.
initonce.Do(func() {
// Disable quic-go's debug message
os.Setenv("QUIC_GO_DISABLE_RECEIVE_BUFFER_WARNING", "true")
managerInstance = &manager{}
radioInstance = &radio{}
// Generate some default options.
_, randomPineconeIdentity, randomPineconeIdentityErr := ed25519.GenerateKey(nil)
if randomPineconeIdentityErr != nil {
panic(fmt.Errorf("fatal error while generating pinecone identity for manager defaults: %e", randomPineconeIdentityErr))
panic(fmt.Errorf("fatal error while generating pinecone identity for radio defaults: %e", randomPineconeIdentityErr))
}
defaults := configSnapshot{
@ -460,12 +459,12 @@ func GetInstance() Manager {
// Set default config values to ensure that the config is never
// in an unusable state and allow for sane options without setting
// everything manually.
managerInstance.conf.configSnapshot = defaults
radioInstance.conf.configSnapshot = defaults
// Init communication channels.
managerInstance.txq = make(chan proto.Packet)
managerInstance.rxq = make(chan proto.Packet)
radioInstance.txq = make(chan proto.Packet)
radioInstance.rxq = make(chan proto.Packet)
})
return managerInstance
return radioInstance
}

View File

@ -1,4 +1,4 @@
package pmanager
package radio
/*

View File

@ -14,8 +14,8 @@ import (
"sync"
"time"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/pmanager"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/proto"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/radio"
"dev.l1qu1d.net/wraith-labs/wraith/wraith/libwraith"
)
@ -43,7 +43,7 @@ type ModulePinecomms struct {
StaticPeers []string
}
func (m *ModulePinecomms) handleRequest(ctx context.Context, w *libwraith.Wraith, pm pmanager.Manager, packet proto.Packet) {
func (m *ModulePinecomms) handleRequest(ctx context.Context, w *libwraith.Wraith, pr radio.Radio, packet proto.Packet) {
//
// Validate and process the packet.
@ -130,7 +130,7 @@ func (m *ModulePinecomms) handleRequest(ctx context.Context, w *libwraith.Wraith
return
}
pm.Send(ctx, proto.Packet{
pr.Send(ctx, proto.Packet{
Peer: packet.Peer,
Method: http.MethodPost,
Route: proto.ROUTE_RESPONSE,
@ -155,24 +155,24 @@ func (m *ModulePinecomms) Mainloop(ctx context.Context, w *libwraith.Wraith) {
}
// Get a struct for managing pinecone connections.
pm := pmanager.GetInstance()
pr := radio.GetInstance()
//
// Configure pinecone manager.
//
pm.SetPineconeIdentity(m.OwnPrivKey)
pm.SetInboundAddr(m.ListenTcp)
pm.SetWebserverAddr(m.ListenWs)
pm.SetUseMulticast(m.UseMulticast)
pm.SetStaticPeers(m.StaticPeers)
pr.SetPineconeIdentity(m.OwnPrivKey)
pr.SetInboundAddr(m.ListenTcp)
pr.SetWebserverAddr(m.ListenWs)
pr.SetUseMulticast(m.UseMulticast)
pr.SetStaticPeers(m.StaticPeers)
// Start the pinecone manager and make sure it stops when
// the module does.
defer func() {
pm.Stop()
pr.Stop()
}()
go pm.Start()
go pr.Start()
//
// Run the module.
@ -226,7 +226,7 @@ func (m *ModulePinecomms) Mainloop(ctx context.Context, w *libwraith.Wraith) {
}
// Send the packet.
pm.Send(ctx, proto.Packet{
pr.Send(ctx, proto.Packet{
Peer: hex.EncodeToString(m.AdminPubKey),
Method: http.MethodPost,
Route: proto.ROUTE_HEARTBEAT,
@ -239,7 +239,7 @@ func (m *ModulePinecomms) Mainloop(ctx context.Context, w *libwraith.Wraith) {
// Start receiving messages.
// Background context is okay because the channel will be closed
// when the manager exits further down anyway.
recv := pm.RecvChan(context.Background())
recv := pr.RecvChan(context.Background())
// Mainloop.
for {
@ -252,7 +252,7 @@ func (m *ModulePinecomms) Mainloop(ctx context.Context, w *libwraith.Wraith) {
switch packet.Route {
case proto.ROUTE_REQUEST:
// Launch a goroutine to handle the request and issue a response.
go m.handleRequest(ctx, w, pm, packet)
go m.handleRequest(ctx, w, pr, packet)
}
}
}