Skip to content

Commit

Permalink
fix: typo (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
woorui authored Sep 22, 2023
1 parent b0055e3 commit 1ee0f1b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
4 changes: 2 additions & 2 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func (c *Client) runBackground(ctx context.Context, addr string, conn quic.Conne
for {
select {
case <-c.ctx.Done():
fs.underlying.Close()
fs.Close()
return
case <-ctx.Done():
fs.underlying.Close()
fs.Close()
return
case f := <-c.writeFrameChan:
if err := fs.WriteFrame(f); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions core/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewConnector(ctx context.Context) *Connector {
}

// Store stores Connection to Connector,
// If the connID is the same twice, the new conntion will replace the old conntion.
// If the connID is the same twice, the new connection will replace the old connection.
// If Connector be closed, The function will return ErrConnectorClosed.
func (c *Connector) Store(connID string, conn Connection) error {
select {
Expand All @@ -44,8 +44,8 @@ func (c *Connector) Store(connID string, conn Connection) error {
return nil
}

// Remove removes the conntion with the specified connID.
// If the Connector does not have a conntion with the given connID, no action is taken.
// Remove removes the connection with the specified connID.
// If the Connector does not have a connection with the given connID, no action is taken.
// If Connector be closed, The function will return ErrConnectorClosed.
func (c *Connector) Remove(connID string) error {
select {
Expand All @@ -60,7 +60,7 @@ func (c *Connector) Remove(connID string) error {
}

// Get retrieves the Connection with the specified connID.
// If the Connector does not have a conntion with the given connID, return nil and false.
// If the Connector does not have a connection with the given connID, return nil and false.
// If Connector be closed, The function will return ErrConnectorClosed.
func (c *Connector) Get(connID string) (Connection, bool, error) {
select {
Expand Down
19 changes: 9 additions & 10 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"context"
"errors"
"sync"
"time"

Expand All @@ -14,9 +13,9 @@ import (

var ctxPool sync.Pool

// Context is context for stream handling.
// Context is generated subsequent to the arrival of a dataStream and retains pertinent information derived from the dataStream.
// The lifespan of the Context should align with the lifespan of the Stream.
// Context is context for connection handling.
// Context is generated subsequent to the arrival of a connection and retains pertinent information derived from the connection.
// The lifespan of the Context should align with the lifespan of the connection.
type Context struct {
// Connection is the connection used for reading and writing frames.
Connection Connection
Expand All @@ -32,7 +31,7 @@ type Context struct {
Keys map[string]any
// BaseLogger is the base logger.
BaseLogger *slog.Logger
// Using Logger to log in stream handler scope, Logger is frame-level logger.
// Using Logger to log in connection handler scope, Logger is frame-level logger.
Logger *slog.Logger
}

Expand Down Expand Up @@ -87,9 +86,9 @@ func (c *Context) Value(key any) any {
}

// newContext returns a new YoMo context that implements the standard library `context.Context` interface.
// The YoMo context is used to manage the lifecycle of a connection and provides a way to pass data and metadata between stream processing functions.
// The lifecycle of the context is equal to the lifecycle of the connection that it is associated with.
// The context can be used to manage timeouts, cancellations, and other aspects of stream processing.
// The YoMo context is used to manage the lifecycle of a connection and provides a way to pass data and metadata
// between connection processing functions. The lifecycle of the context is equal to the lifecycle of the connection
// that it is associated with. The context can be used to manage timeouts, cancellations, and other aspects of connection processing.
func newContext(conn Connection, route router.Route, logger *slog.Logger) (c *Context) {
v := ctxPool.Get()
if v == nil {
Expand All @@ -116,7 +115,7 @@ func newContext(conn Connection, route router.Route, logger *slog.Logger) (c *Co
func (c *Context) WithFrame(f frame.Frame) error {
df, ok := f.(*frame.DataFrame)
if !ok {
return errors.New("connection only transmit data frame")
return nil
}

fmd, err := metadata.Decode(df.Metadata)
Expand All @@ -138,7 +137,7 @@ func (c *Context) WithFrame(f frame.Frame) error {

// CloseWithError close dataStream with an error string.
func (c *Context) CloseWithError(errString string) {
c.Logger.Debug("connection closed", "error", errString)
c.Logger.Debug("connection closed", "err", errString)

err := c.Connection.CloseWithError(errString)
if err == nil {
Expand Down
19 changes: 10 additions & 9 deletions core/frame/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// 3. DataFrame
// 4. BackflowFrame
// 5. RejectedFrame
// 6. GoawayFrame
//
// Read frame comments to understand the role of the frame.
type Frame interface {
Expand All @@ -25,7 +26,7 @@ type Frame interface {
// Type defined The type of frame.
type Type byte

// DataFrame carries tagged data to transmit across DataStream.
// DataFrame carries tagged data to transmit across connection.
type DataFrame struct {
// Metadata stores additional data beyond the Payload,
// it is an map[string]string{} that be encoded in msgpack.
Expand All @@ -40,8 +41,8 @@ type DataFrame struct {
func (f *DataFrame) Type() Type { return TypeDataFrame }

// The HandshakeFrame is the frame through which the client obtains a new connection from the server.
// It include essential details required for the creation of a fresh DataStream.
// The server then generates the DataStream utilizing this provided information.
// It includes essential details required for the creation of a fresh connection.
// The server then generates the connection utilizing this provided information.
type HandshakeFrame struct {
// Name is the name of the dataStream that will be created.
Name string
Expand All @@ -51,9 +52,9 @@ type HandshakeFrame struct {
ClientType byte
// ObserveDataTags is the ObserveDataTags of the dataStream that will be created.
ObserveDataTags []Tag
// AuthName.
// AuthName is the authentication name.
AuthName string
// AuthPayload.
// AuthPayload is the authentication payload.
AuthPayload string
}

Expand All @@ -67,8 +68,8 @@ type HandshakeAckFrame struct{}
// Type returns the type of HandshakeAckFrame.
func (f *HandshakeAckFrame) Type() Type { return TypeHandshakeAckFrame }

// The BackflowFrame is used to receive the processed result of a DataStream with StreamFunction type
// and forward it to a DataStream with StreamSource type.
// The BackflowFrame is used to receive the processed result of a connection with StreamFunction type
// and forward it to a connection with StreamSource type.
type BackflowFrame struct {
// Tag is used for data router.
Tag Tag
Expand All @@ -79,7 +80,7 @@ type BackflowFrame struct {
// Type returns the type of BackflowFrame.
func (f *BackflowFrame) Type() Type { return TypeBackflowFrame }

// RejectedFrame is used to reject a ControlStream request.
// RejectedFrame is used to reject a client request.
type RejectedFrame struct {
// Message encapsulates the rationale behind the rejection of the request.
Message string
Expand All @@ -99,7 +100,7 @@ func (f *GoawayFrame) Type() Type { return TypeGoawayFrame }

const (
TypeDataFrame Type = 0x3F // TypeDataFrame is the type of DataFrame.
TypeHandshakeFrame Type = 0x31 // TypeHandshakeFrame is the type of PayloadFrame.
TypeHandshakeFrame Type = 0x31 // TypeHandshakeFrame is the type of HandshakeFrame.
TypeHandshakeAckFrame Type = 0x29 // TypeHandshakeAckFrame is the type of HandshakeAckFrame.
TypeRejectedFrame Type = 0x39 // TypeRejectedFrame is the type of RejectedFrame.
TypeBackflowFrame Type = 0x2D // TypeBackflowFrame is the type of BackflowFrame.
Expand Down
7 changes: 3 additions & 4 deletions core/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (

// M stores additional information about the application.
//
// There are three types of metadata in yomo:
// There are two types of metadata in yomo:
// 1. Metadata from `Authentication.Authenticate()`, This is connection-level metadata.
// 2. Metadata from the handshake, This is stream-level metadata.
// 3. Metadata from the DataFrame, This is frame-level metadata.
// 2. Metadata from the DataFrame, This is frame-level metadata.
//
// the main responsibility of Metadata is to route messages to stream functions.
// the main responsibility of Metadata is to route messages to connection handler.
type M map[string]string

// New creates an M from a given key-values map.
Expand Down
2 changes: 1 addition & 1 deletion core/router/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRouter(t *testing.T) {
assert.NoError(t, err)

ids = route.GetForwardRoutes(frame.Tag(1))
assert.Equal(t, []string{"conn-2", "conn-3"}, ids)
assert.ElementsMatch(t, []string{"conn-2", "conn-3"}, ids)

router.Clean()

Expand Down

0 comments on commit 1ee0f1b

Please sign in to comment.