Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
df5f70f
mod/gateway: WIP
Rekseto Mar 10, 2026
1f0e767
mod/gateway: WIP
Rekseto Mar 11, 2026
6ae241f
mod/gateway: WIP
Rekseto Mar 11, 2026
47a074d
mod/tcp: add errors related to ephemeral
Rekseto Mar 11, 2026
962ea94
mod/gateway: add log
Rekseto Mar 11, 2026
5e7829a
mod/gateway: binding to gateways from config
Rekseto Mar 11, 2026
415279e
mod/gateway: fix suffix
Rekseto Mar 11, 2026
edd1a65
mod/gateway: add logging
Rekseto Mar 11, 2026
8ddf605
mod/gateway: add ZoneNetwork when dialing
Rekseto Mar 11, 2026
82c0dec
mod/gateway: WIP
Rekseto Mar 12, 2026
89191f2
mod/gateway: WIP
Rekseto Mar 12, 2026
d4bae63
mod/gateway: WIP
Rekseto Mar 12, 2026
42025eb
mod/gateway: proper closing conns
Rekseto Mar 12, 2026
532f048
mod/gateway: WIP
Rekseto Mar 12, 2026
52caa31
mod/gateway: WIP
Rekseto Mar 12, 2026
f70d5bb
mod/gateway: improve socket pool
Rekseto Mar 12, 2026
7fb2776
mod/gateway: maintain_binding_task.go
Rekseto Mar 12, 2026
f291817
mod/gateway: improvements in SocketPool
Rekseto Mar 12, 2026
837de74
mod/gateway: minor fixes
Rekseto Mar 12, 2026
3629b65
mod/gateway: log fix
Rekseto Mar 12, 2026
a3691e6
mod/gateway: small fixes
Rekseto Mar 12, 2026
f44db73
mod/gateway: adding EventReceicer to maintain_binding_task.go
Rekseto Mar 12, 2026
5a00503
mod/gateway: minor refactors
Rekseto Mar 13, 2026
c23aabc
mod/gateway: add comments
Rekseto Mar 13, 2026
ad0f831
mod/gateway: adding GatewayID to socket
Rekseto Mar 13, 2026
647a8d6
mod/gateway: better logs
Rekseto Mar 13, 2026
e78b89b
mod/gateway: log improvements
Rekseto Mar 13, 2026
95be9f1
mod/gateway: add ZoneNetwork for fallback
Rekseto Mar 13, 2026
3209664
mod/gateway: add ZoneNetwork
Rekseto Mar 13, 2026
5cabe2b
mod/gateway: adding endpoints resolvers & service discoverer
Rekseto Mar 13, 2026
3b2b7de
mod/gateway: change comment
Rekseto Mar 13, 2026
e6e6b8a
mod/gateway: discovering dead connections
Rekseto Mar 14, 2026
2ada936
mod/gateway: add comment
Rekseto Mar 14, 2026
fdedad9
mod/gateway: simplification
Rekseto Mar 14, 2026
22b969c
mod/gateway: add singalling on gw
Rekseto Mar 14, 2026
f0e1587
mod/gateway: pingFrame
Rekseto Mar 14, 2026
8cc1e6a
mod/gateway: WIP
Rekseto Mar 14, 2026
569f273
mod/gateway: WIP
Rekseto Mar 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions astral/router.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package astral

import (
"context"
"io"
)

type Router interface {
RouteQuery(ctx *Context, q *Query, w io.WriteCloser) (io.WriteCloser, error)
}

type RouteQueryFunc func(ctx context.Context, q *Query, w io.WriteCloser) (io.WriteCloser, error)
type RouteQueryFunc func(ctx *Context, q *Query, w io.WriteCloser) (io.WriteCloser, error)
16 changes: 16 additions & 0 deletions mod/gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# gateway

## Configuration

`gateway.yaml`:

```yaml
gateway:
enabled: true
listen:
- tcp:<public-ip>:6000

visibility: public
init_conns: 1
max_conns: 8
```
24 changes: 24 additions & 0 deletions mod/gateway/client/bind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gateway

import (
"github.com/cryptopunkscc/astrald/astral"
"github.com/cryptopunkscc/astrald/astral/channel"
"github.com/cryptopunkscc/astrald/lib/query"
gw "github.com/cryptopunkscc/astrald/mod/gateway"
)

func (c *Client) Bind(ctx *astral.Context, visibility gw.Visibility) (*gw.Socket, error) {
ch, err := c.queryCh(ctx, gw.MethodBind, query.Args{"visibility": string(visibility)})
if err != nil {
return nil, err
}
defer ch.Close()

var socket *gw.Socket
err = ch.Switch(
channel.Expect(&socket),
channel.PassErrors,
)

return socket, err
}
36 changes: 36 additions & 0 deletions mod/gateway/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gateway

import (
"github.com/cryptopunkscc/astrald/astral"
"github.com/cryptopunkscc/astrald/astral/channel"
"github.com/cryptopunkscc/astrald/lib/astrald"
)

type Client struct {
astral *astrald.Client
targetID *astral.Identity
}

var defaultClient *Client

func New(targetID *astral.Identity, a *astrald.Client) *Client {
if a == nil {
a = astrald.Default()
}
return &Client{astral: a, targetID: targetID}
}

func Default() *Client {
if defaultClient == nil {
defaultClient = New(nil, nil)
}
return defaultClient
}

func SetDefault(client *Client) {
defaultClient = client
}

func (c *Client) queryCh(ctx *astral.Context, method string, args any, cfg ...channel.ConfigFunc) (*channel.Channel, error) {
return c.astral.WithTarget(c.targetID).QueryChannel(ctx, method, args, cfg...)
}
24 changes: 24 additions & 0 deletions mod/gateway/client/connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gateway

import (
"github.com/cryptopunkscc/astrald/astral"
"github.com/cryptopunkscc/astrald/astral/channel"
"github.com/cryptopunkscc/astrald/lib/query"
gw "github.com/cryptopunkscc/astrald/mod/gateway"
)

func (c *Client) Connect(ctx *astral.Context, target *astral.Identity) (*gw.Socket, error) {
ch, err := c.queryCh(ctx, gw.MethodConnect, query.Args{"target": target.String()})
if err != nil {
return nil, err
}
defer ch.Close()

var socket *gw.Socket
err = ch.Switch(
channel.Expect(&socket),
channel.PassErrors,
)

return socket, err
}
25 changes: 25 additions & 0 deletions mod/gateway/client/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gateway

import (
"github.com/cryptopunkscc/astrald/astral"
"github.com/cryptopunkscc/astrald/astral/channel"
"github.com/cryptopunkscc/astrald/lib/query"
gw "github.com/cryptopunkscc/astrald/mod/gateway"
)

func (c *Client) List(ctx *astral.Context) ([]*astral.Identity, error) {
ch, err := c.queryCh(ctx, gw.MethodList, query.Args{})
if err != nil {
return nil, err
}
defer ch.Close()

var list []*astral.Identity
err = ch.Switch(
channel.Collect(&list),
channel.StopOnEOS,
channel.PassErrors,
)

return list, err
}
8 changes: 8 additions & 0 deletions mod/gateway/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gateway

import "errors"

var ErrUnauthorized = errors.New("unauthorized")
var ErrTargetNotReachable = errors.New("target not reachable")
var ErrInvalidGateway = errors.New("invalid gateway")
var ErrSocketUnreachable = errors.New("socket unreachable")
7 changes: 7 additions & 0 deletions mod/gateway/maintain_binding_task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gateway

import "github.com/cryptopunkscc/astrald/mod/scheduler"

type MaintainBindingTask interface {
scheduler.Task
}
13 changes: 13 additions & 0 deletions mod/gateway/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gateway

const ModuleName = "gateway"

const (
MethodBind = "gateway.node_bind"
MethodConnect = "gateway.node_connect"
MethodList = "gateway.node_list"
MethodRoute = "gateway.route"
)

type Module interface {
}
8 changes: 8 additions & 0 deletions mod/gateway/ping_frame.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gateway

const (
BytePing = byte(0x00)
BytePong = byte(0x01)
ByteSignalGo = byte(0x02)
ByteSignalReady = byte(0x03)
)
25 changes: 25 additions & 0 deletions mod/gateway/socket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gateway

import (
"io"

"github.com/cryptopunkscc/astrald/astral"
"github.com/cryptopunkscc/astrald/mod/exonet"
)

// Socket describes a raw connection point at the gateway. The recipient opens
// a raw exonet connection to the Endpoint and sends Nonce as the first bytes
// to identify itself to the gateway.
type Socket struct {
Endpoint exonet.Endpoint
Nonce astral.Nonce
}

func (Socket) ObjectType() string { return "mod.gateway.socket" }

func (s Socket) WriteTo(w io.Writer) (int64, error) { return astral.Objectify(&s).WriteTo(w) }
func (s *Socket) ReadFrom(r io.Reader) (int64, error) { return astral.Objectify(s).ReadFrom(r) }

func init() {
astral.Add(&Socket{})
}
Loading