Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

piko: integrate agent/server v2 #67

Merged
merged 4 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
- name: Integration Tests
run: go test ./... -tags integration -v

- name: System Tests
run: go test ./tests -tags system -v

lint:
runs-on: ubuntu-latest
needs: build
Expand Down
14 changes: 7 additions & 7 deletions agentv2/client/piko.go → agent/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package piko
package client

import (
"context"
Expand All @@ -11,17 +11,17 @@ const (
defaultURL = "ws://localhost:8001"
)

// Piko manages registering and listening on endpoints.
// Client manages registering listeners with Piko.
//
// The client establishes an outbound-only connection to the server for each
// listener. Proxied connections for the listener are then multiplexed over
// that outbound connection. Therefore the client never exposes a port.
type Piko struct {
type Client struct {
options options
logger log.Logger
}

func New(opts ...Option) *Piko {
func New(opts ...Option) *Client {
options := options{
token: "",
url: defaultURL,
Expand All @@ -31,7 +31,7 @@ func New(opts ...Option) *Piko {
o.apply(&options)
}

return &Piko{
return &Client{
options: options,
logger: options.logger,
}
Expand All @@ -42,6 +42,6 @@ func New(opts ...Option) *Piko {
// Listen will block until the listener has been registered.
//
// The returned [Listener] is a [net.Listener].
func (p *Piko) Listen(ctx context.Context, endpointID string) (Listener, error) {
return listen(ctx, endpointID, p.options, p.logger)
func (c *Client) Listen(ctx context.Context, endpointID string) (Listener, error) {
return listen(ctx, endpointID, c.options, c.logger)
}
14 changes: 3 additions & 11 deletions agentv2/client/listener.go → agent/client/listener.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package piko
package client

import (
"context"
"errors"
"fmt"
"net"
"net/url"
"sync"
"time"

"github.com/andydunstall/piko/pkg/backoff"
Expand Down Expand Up @@ -48,8 +47,7 @@ type Listener interface {
type listener struct {
endpointID string

mux *mux.Session
muxMu sync.Mutex
mux *mux.Session

options options

Expand Down Expand Up @@ -101,9 +99,7 @@ func (l *listener) Accept() (net.Conn, error) {
return nil, err
}

l.muxMu.Lock()
l.mux = mux
l.muxMu.Unlock()
}
}

Expand All @@ -114,11 +110,7 @@ func (l *listener) Addr() net.Addr {
func (l *listener) Close() error {
l.closeCancel()

l.muxMu.Lock()
err := l.mux.Close()
l.muxMu.Unlock()

return err
return l.mux.Close()
}

func (l *listener) EndpointID() string {
Expand Down
2 changes: 1 addition & 1 deletion agentv2/client/options.go → agent/client/options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package piko
package client

import (
"crypto/tls"
Expand Down
Loading
Loading