feat: shared token support #39

Merged
decentral1se merged 1 commits from shared-token into main 2026-11-17 12:17:00 +00:00
9 changed files with 97 additions and 0 deletions
+1
View File
@@ -14,6 +14,7 @@ examples/http-dialer/http-client
examples/http-dialer/http-dialer
examples/jasmine-teehaus/jasmineteehaus
examples/pairchat/pairchat
examples/shared-token/shared-token
examples/simple-pipe/simple-pipe
examples/timeserve/timeserve
examples/withcontext/withcontext
+12
View File
@@ -9,6 +9,8 @@ import (
jt "gomod.cblgh.org/jasmine-teehaus/experimental"
)
var DefaultQuicPort uint16 = 7842
type Option func(*iroh.EndpointBuilder) error
func New(options ...Option) (*iroh.Endpoint, error) {
@@ -81,6 +83,16 @@ func WithRelayMode(rMode *iroh.RelayMode) Option {
}
}
func WithSharedToken(vMap *iroh.RelayMap) Option {
return func(endpointBuilder *iroh.EndpointBuilder) error {
// NOTE(d1): pending the more convenient implementation
// https://github.com/n0-computer/iroh-ffi/issues/307
rMode := iroh.RelayModeCustom(vMap)
endpointBuilder.RelayMode(rMode)
return nil
}
}
func WithSecretKey(secretKey []byte) Option {
return func(endpointBuilder *iroh.EndpointBuilder) error {
return endpointBuilder.SecretKey(secretKey)
+10
View File
@@ -3,3 +3,13 @@
This example shows how to configure the community managed relays of
[`jasmine-teehaus`](https://codeberg.org/cblgh/jasmine-teehaus). This approach
should generally work for other community relays.
This code might not run if the Jasmine Teehaus relays are down or protected by
additional authentication methods in the future. Please consult the upstream
repository linked above.
## Terminal 1
```
./jasmineteehaus
```
+13
View File
@@ -0,0 +1,13 @@
# shared-token
This example shows how to connect to a relay which is protected by a shared
token. **Please note**, this example will not work unless you have a valid
shared token from the [Jasmine Teehaus
community](https://codeberg.org/cblgh/jasmine-teehaus).
## Terminal 1
```
export SHARED_TOKEN=...
./shared-token
```
BIN
View File
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
module git.coopcloud.tech/decentral1se/iroh-go/examples/shared-token
go 1.26.1
require git.coopcloud.tech/decentral1se/iroh-go v0.0.0-20260717110820-68ad06fe2a25
require (
golang.org/x/sync v0.24.0 // indirect
gomod.cblgh.org/jasmine-teehaus v0.0.3 // indirect
)
replace git.coopcloud.tech/decentral1se/iroh-go => ../../
+6
View File
@@ -0,0 +1,6 @@
github.com/magiconair/properties v1.18.12 h1:sT9zQpvTB3B4gzrX0tmZNTEaGyg8Zw55MFYRE32Mr9I=
github.com/magiconair/properties v1.18.12/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
gomod.cblgh.org/jasmine-teehaus v0.0.3 h1:KXdEcJeAo7TqNq98UtPJ/OzmteVuaaoMWy7LK1wZMy4=
gomod.cblgh.org/jasmine-teehaus v0.0.3/go.mod h1:kga45IfEn1aEX2VPxQ8yXA3VcqyDseTIdf68gpWQtrM=
+2
View File
@@ -0,0 +1,2 @@
default:
@go build -ldflags "-s -w" -v ./...
+41
View File
@@ -0,0 +1,41 @@
package main
import (
"fmt"
"os"
iroh "git.coopcloud.tech/decentral1se/iroh-go"
"git.coopcloud.tech/decentral1se/iroh-go/endpoint"
)
func main() {
alpn := iroh.Alpn("iroh-go-shared-token/0")
token := os.Getenv("SHARED_TOKEN")
if token == "" {
fmt.Println("missing SHARED_TOKEN?")
os.Exit(1)
}
vMap := iroh.RelayMapEmpty()
vMap.Insert(iroh.RelayConfig{
Url: "https://jasmine.permacomputing.net",
QuicPort: &endpoint.DefaultQuicPort,
AuthToken: &token,
})
e, err := endpoint.New(
endpoint.WithAlpns(alpn),
endpoint.WithApplyJasmineTeehaus(),
endpoint.WithSharedToken(vMap),
)
if err := iroh.As(err); err != nil {
panic(err)
}
e.Online()
if err := e.Close(); err != nil {
panic(iroh.As(err))
}
}