Skip to content

Commit

Permalink
feat: quic implements FrameConn interface
Browse files Browse the repository at this point in the history
  • Loading branch information
woorui committed Oct 29, 2023
1 parent c440e66 commit e7176c6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"time"

"github.com/yomorun/yomo/core/frame"
"github.com/yomorun/yomo/core/listener"
ynet "github.com/yomorun/yomo/core/net"
"github.com/yomorun/yomo/pkg/frame-codec/y3codec"
"github.com/yomorun/yomo/pkg/id"
"github.com/yomorun/yomo/pkg/listener/yquic"
yquic "github.com/yomorun/yomo/pkg/netimpl/quic"
oteltrace "go.opentelemetry.io/otel/trace"
"golang.org/x/exp/slog"
)
Expand Down Expand Up @@ -69,7 +69,7 @@ func NewClient(appName, zipperAddr string, clientType ClientType, opts ...Client
}
}

func (c *Client) connect(ctx context.Context, addr string) (listener.FrameConn, error) {
func (c *Client) connect(ctx context.Context, addr string) (ynet.FrameConn, error) {
conn, err := yquic.DialAddr(ctx, addr, y3codec.Codec(), y3codec.PacketReadWriter(), c.opts.tlsConfig, c.opts.quicConfig)
if err != nil {
return conn, err
Expand Down Expand Up @@ -104,7 +104,7 @@ func (c *Client) connect(ctx context.Context, addr string) (listener.FrameConn,
}
}

func (c *Client) runBackground(ctx context.Context, conn listener.FrameConn) {
func (c *Client) runBackground(ctx context.Context, conn ynet.FrameConn) {
reconnection := make(chan struct{})

go c.handleReadFrames(conn, reconnection)
Expand Down Expand Up @@ -228,7 +228,7 @@ func (c *Client) Wait() {
<-c.ctx.Done()
}

func (c *Client) handleReadFrames(fconn listener.FrameConn, reconnection chan struct{}) {
func (c *Client) handleReadFrames(fconn ynet.FrameConn, reconnection chan struct{}) {
for {
f, err := fconn.ReadFrame()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions core/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package core

import (
"github.com/yomorun/yomo/core/frame"
"github.com/yomorun/yomo/core/listener"
"github.com/yomorun/yomo/core/metadata"
ynet "github.com/yomorun/yomo/core/net"
)

// ConnectionInfo holds the information of connection.
Expand All @@ -24,7 +24,7 @@ type ConnectionInfo interface {
// Connection be used to read and write frames, and be managed by Connector.
type Connection interface {
ConnectionInfo
FrameConn() listener.FrameConn
FrameConn() ynet.FrameConn
}

type connection struct {
Expand All @@ -33,12 +33,12 @@ type connection struct {
clientType ClientType
metadata metadata.M
observeDataTags []uint32
fconn listener.FrameConn
fconn ynet.FrameConn
}

func newConnection(
name string, id string, clientType ClientType, md metadata.M, tags []uint32,
fconn listener.FrameConn) *connection {
fconn ynet.FrameConn) *connection {
return &connection{
name: name,
id: id,
Expand Down Expand Up @@ -69,6 +69,6 @@ func (c *connection) ClientType() ClientType {
return c.clientType
}

func (c *connection) FrameConn() listener.FrameConn {
func (c *connection) FrameConn() ynet.FrameConn {
return c.fconn
}
2 changes: 1 addition & 1 deletion core/listener/listener.go → core/net/net.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package listener
package ynet

import (
"context"
Expand Down
14 changes: 7 additions & 7 deletions core/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

"github.com/yomorun/yomo/core/auth"
"github.com/yomorun/yomo/core/frame"
"github.com/yomorun/yomo/core/listener"
"github.com/yomorun/yomo/core/metadata"
ynet "github.com/yomorun/yomo/core/net"
"github.com/yomorun/yomo/core/router"
"golang.org/x/exp/slog"

// authentication implements, Currently, only token authentication is implemented
_ "github.com/yomorun/yomo/pkg/auth"
"github.com/yomorun/yomo/pkg/frame-codec/y3codec"
"github.com/yomorun/yomo/pkg/listener/yquic"
yquic "github.com/yomorun/yomo/pkg/netimpl/quic"
pkgtls "github.com/yomorun/yomo/pkg/tls"
oteltrace "go.opentelemetry.io/otel/trace"
)
Expand All @@ -47,7 +47,7 @@ type Server struct {
startHandlers []FrameHandler
beforeHandlers []FrameHandler
afterHandlers []FrameHandler
listener listener.Listener
listener ynet.Listener
logger *slog.Logger
tracerProvider oteltrace.TracerProvider
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (s *Server) ListenAndServe(ctx context.Context, addr string) error {
return s.Serve(ctx, conn)
}

func (s *Server) handshake(fconn listener.FrameConn) (bool, router.Route, Connection) {
func (s *Server) handshake(fconn ynet.FrameConn) (bool, router.Route, Connection) {
var gerr error

defer func() {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *Server) handshake(fconn listener.FrameConn) (bool, router.Route, Connec
}
}

func (s *Server) handleConnection(fconn listener.FrameConn, logger *slog.Logger) {
func (s *Server) handleConnection(fconn ynet.FrameConn, logger *slog.Logger) {
ok, route, conn := s.handshake(fconn)
if !ok {
logger.Error("handshake failed")
Expand Down Expand Up @@ -223,7 +223,7 @@ func (s *Server) handleRoute(hf *frame.HandshakeFrame, md metadata.M) (router.Ro
return route, nil
}

func (s *Server) handleHandshakeFrame(fconn listener.FrameConn, hf *frame.HandshakeFrame) (Connection, error) {
func (s *Server) handleHandshakeFrame(fconn ynet.FrameConn, hf *frame.HandshakeFrame) (Connection, error) {
md, ok := auth.Authenticate(s.opts.auths, hf)

if !ok {
Expand Down Expand Up @@ -290,7 +290,7 @@ func (s *Server) Close() error {
return nil
}

func closeServer(downstreams map[string]Downstream, connector *Connector, listener listener.Listener, router router.Router) error {
func closeServer(downstreams map[string]Downstream, connector *Connector, listener ynet.Listener, router router.Router) error {
for _, ds := range downstreams {
ds.Close()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/listener/yquic/listener.go → pkg/netimpl/quic/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/quic-go/quic-go"
"github.com/yomorun/yomo/core/frame"
"github.com/yomorun/yomo/core/listener"
ynet "github.com/yomorun/yomo/core/net"
)

// ErrConnClosed is returned when the connection is closed.
Expand Down Expand Up @@ -210,7 +210,7 @@ func ListenAddr(
}

// Accept accepts FrameConns.
func (listener *Listener) Accept(ctx context.Context) (listener.FrameConn, error) {
func (listener *Listener) Accept(ctx context.Context) (ynet.FrameConn, error) {
qconn, err := listener.underlying.Accept(ctx)
if err != nil {
return nil, err
Expand Down
File renamed without changes.

0 comments on commit e7176c6

Please sign in to comment.