transport

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 9

Documentation

Overview

Package transport provides network transport abstractions This file defines the Channel interface which represents a network communication channel

Package transport SChannel is a struct that represents a secure channel for communication It implements the conn interface from net package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel interface {
	io.Reader

	io.Writer

	// conn net.Conn provides basic network connection functionality
	net.Conn

	// GetReader returns the reader part of the channel
	// This can be used to get a specific reader implementation
	GetReader() io.Reader

	// GetWriter returns the writer part of the channel
	// This can be used to get a specific writer implementation
	GetWriter() io.Writer

	// RemoteAddr returns the remote network address
	// This overrides the method from net.Conn to provide
	// a more specific implementation for this transport
	RemoteAddr() net.Addr

	// LocalAddr returns the local network address
	// This overrides the method from net.Conn to provide
	// a more specific implementation for this transport
	LocalAddr() net.Addr

	// GetConn returns the underlying network connection
	// This provides access to the raw network connection
	// for cases where direct access is needed
	GetConn() net.Conn

	// GetId returns the unique identifier for the channel
	GetId() string

	// Done returns a channel that is closed when the channel is closed
	// This can be used to wait for the channel to be closed
	//Close
	Done() <-chan struct{}

	// IsClose isClose.
	IsClose() bool

	SendTo(by []byte, addr net.Addr) (int, error)
	//
	// GetAttr
	//  @Description: getKey.
	//  @param key
	//
	GetAttr(key lang.KeyType) (interface{}, bool)

	// OnClose CloseEvent The Channel Setter CloseEvent
	OnClose(event CloseEvent)

	LastTime() time.Time

	ActiveTime() time.Time
}

Channel interface represents a network communication channel It combines io.Reader and io.Writer with net.Conn to provide a comprehensive interface for network operations. This interface is designed to be implemented by different transport protocols while providing a consistent API for upper layers.

type CloseEvent

type CloseEvent func(channel Channel)

type SChannel

type SChannel struct {
	IsOpenTunnel bool
	// contains filtered or unexported fields
}

SChannel struct holds the secure channel information r and w are the reader and writer for the channel stream is the underlying smux stream buf is a buffer for storing data temporarily isBindTunnel indicates if the channel is bound to a tunnel

func NewSChannel

func NewSChannel(
	stream *smux.Stream,
	parent context.Context,
	isOpenTunnel bool) *SChannel

NewSChannel creates a new SChannel with the given smux stream It initializes a pipe for reading and writing

func (*SChannel) ActiveTime

func (c *SChannel) ActiveTime() time.Time

func (*SChannel) AddAttr

func (c *SChannel) AddAttr(key lang.KeyType, value interface{})

func (*SChannel) Close

func (c *SChannel) Close() error

Close closes the SChannel by closing the underlying stream

func (*SChannel) Ctx

func (c *SChannel) Ctx() context.Context

func (*SChannel) Done

func (c *SChannel) Done() <-chan struct{}

func (*SChannel) GetAttr

func (c *SChannel) GetAttr(key lang.KeyType) (interface{}, bool)

func (*SChannel) GetConn

func (c *SChannel) GetConn() net.Conn

GetConn returns the underlying connection

func (*SChannel) GetId

func (c *SChannel) GetId() string

func (*SChannel) GetReader

func (c *SChannel) GetReader() io.Reader

GetReader returns the reader for this channel

func (*SChannel) GetWriter

func (c *SChannel) GetWriter() io.Writer

GetWriter returns the writer for this channel

func (*SChannel) IsClose

func (c *SChannel) IsClose() bool

func (*SChannel) IsHealthy

func (c *SChannel) IsHealthy() bool

func (*SChannel) LastTime

func (c *SChannel) LastTime() time.Time

func (*SChannel) LocalAddr

func (c *SChannel) LocalAddr() net.Addr

LocalAddr returns the local network address

func (*SChannel) OnClose

func (c *SChannel) OnClose(event CloseEvent)

func (*SChannel) Read

func (c *SChannel) Read(p []byte) (n int, err error)

Read reads data into p

func (*SChannel) RemoteAddr

func (c *SChannel) RemoteAddr() net.Addr

RemoteAddr returns the remote network address

func (*SChannel) SendTo

func (c *SChannel) SendTo([]byte, net.Addr) (int, error)

func (*SChannel) SetDeadline

func (c *SChannel) SetDeadline(t time.Time) error

SetDeadline sets the deadline for both read and write operations

func (*SChannel) SetReadDeadline

func (c *SChannel) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for read operations

func (*SChannel) SetWriteDeadline

func (c *SChannel) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for write operations

func (*SChannel) Write

func (c *SChannel) Write(p []byte) (n int, err error)

Write writes data from p

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL