This commit is contained in:
Risotto Bias 2025-04-07 05:12:42 -06:00
parent c70dd77203
commit cbc276acf0
10 changed files with 36 additions and 13 deletions

View file

@ -1,7 +1,9 @@
# Trade Example
- export a key `export KEY_PASSWD="blarg test"`
- spawn two servers: `./example 8080 &` `./example 8081`
- spawn two servers:
- `./example 8080 ./1.key &`
- `./example 8081 ./2.key &`
- register the servers:
- `./trade servers add localhost:8080`
- `./trade servers add localhost:8081`

View file

@ -15,11 +15,13 @@ func main() {
fmt.Println("no KEY_PASSWD environment variable")
os.Exit(1)
}
if len(os.Args) != 1 {
fmt.Println("no key path specified")
if len(os.Args) != 4 {
fmt.Println("usage: ./example port keypath storepath")
os.Exit(1)
}
keypath := os.Args[1]
port := os.Args[2]
keypath := os.Args[3]
storepath := os.Args[4]
// spawn trade KV
trade.Load(passwd, keypath, GLOBAL_KV)
// load self key or generate one

View file

@ -1,6 +1,6 @@
package example
import "git.bivouac.wiki/go/gobstore"
import "git.bivouac.wiki/use/gobstore"
var GLOBAL_KV gobstore.GobStore[string]

4
get.go
View file

@ -1,11 +1,11 @@
package trade
// Get retrieves and stores a value from peers
func (t *KV) Get(k string) (any, error) {
func (kv *KV[t]) Get(k string) (t, error) {
// debate over expiry of values or using a common KV interface...
// like using kvcache...
// try getting locally:
res, ok := t.local[k]
res, ok := kv.local[k]
if !ok {
// for peer in peers, grab value:
}

1
go.mod
View file

@ -5,6 +5,7 @@ go 1.22.5
require (
aead.dev/minisign v0.3.0
filippo.io/age v1.2.1
git.bivouac.wiki/use/gobstore v0.0.0-20250112095151-9564d5656a22
)
require (

2
go.sum
View file

@ -2,6 +2,8 @@ aead.dev/minisign v0.3.0 h1:8Xafzy5PEVZqYDNP60yJHARlW1eOQtsKNp/Ph2c0vRA=
aead.dev/minisign v0.3.0/go.mod h1:NLvG3Uoq3skkRMDuc3YHpWUTMTrSExqm+Ij73W13F6Y=
filippo.io/age v1.2.1 h1:X0TZjehAZylOIj4DubWYU1vWQxv9bJpo+Uu2/LGhi1o=
filippo.io/age v1.2.1/go.mod h1:JL9ew2lTN+Pyft4RiNGguFfOpewKwSHm5ayKD/A4004=
git.bivouac.wiki/use/gobstore v0.0.0-20250112095151-9564d5656a22 h1:97PasJ12dLCrveYbH9HioN3KedBrC8KTVopDuiU07BI=
git.bivouac.wiki/use/gobstore v0.0.0-20250112095151-9564d5656a22/go.mod h1:cfFzcWO3zypVYiJrgQLSLil5HPWFXaB/JP7rUJQRCZU=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=

20
kv.go
View file

@ -1,5 +1,21 @@
package trade
type KV struct {
local map[string]any
type Store interface {
Get(string) any
Set(string, any)
Del(string)
}
type KV[t any] struct {
local map[string]t
store Store
peers []Server
}
func NewKV[t any](s Store) KV[t] {
res := KV[t]{
local: make(map[string]t),
store: s,
}
return res
}

View file

@ -1,7 +1,7 @@
package trade
// add a server at an address
func RegAddServer(a Addr) error {
func RegAddServer(addr string) error {
// read the server's key
// check signature
// sign servers key

View file

@ -1,6 +1,6 @@
package trade
// RegDelServer revokes a server's trade access
func RegDelServer() {
func RegDelServer(addr string) {
}

4
set.go
View file

@ -1,9 +1,9 @@
package trade
// Set stores & sends a value to all verified peers
func (t *KV) Set(k string, v any) error {
func (kv *KV[t]) Set(k string, v t) error {
// store in local cache
t.local[k] = v
kv.local[k] = v
// for server in servers
return err