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

fix: typo #628

Merged
merged 1 commit into from
Sep 22, 2023
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
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 @@
for {
select {
case <-c.ctx.Done():
fs.underlying.Close()
fs.Close()
return
case <-ctx.Done():
fs.underlying.Close()
fs.Close()

Check warning on line 144 in core/client.go

View check run for this annotation

Codecov / codecov/patch

core/client.go#L144

Added line #L144 was not covered by tests
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 @@

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

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

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 @@
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 @@
}

// 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 (c *Context) WithFrame(f frame.Frame) error {
df, ok := f.(*frame.DataFrame)
if !ok {
return errors.New("connection only transmit data frame")
return nil

Check warning on line 118 in core/context.go

View check run for this annotation

Codecov / codecov/patch

core/context.go#L118

Added line #L118 was not covered by tests
}

fmd, err := metadata.Decode(df.Metadata)
Expand All @@ -138,7 +137,7 @@

// 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)

Check warning on line 140 in core/context.go

View check run for this annotation

Codecov / codecov/patch

core/context.go#L140

Added line #L140 was not covered by tests

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