Teleport2.0 implements a new Golang TCP Socket framework, which is versatile, efficient and flexible! It can be used in peer-to-peer communication, RPC, long connection gateway, micro service, push service, game service and other fields.
Characteristics of 1.
-
Peer communication between the server and the client, and the API methods are basically the same
-
The underlying communication packet consists of Header and Body
-
Support for separate custom Header and Body encoding types, such as JSON Protobuf
-
Body supports GZIP compression
-
The Header contains the status code and its description text
-
Supports push, pull, reply and other communication modes
-
Support plug-in mechanism, you can customize authentication, heartbeat, microservice registry, statistics plug-in, etc
-
Both servers and clients can be gracefully restarted or shut down
-
Supports the reverse proxy function
-
The detailed log information supports the printing of detailed information about the input and output messages (status code, message header, and message body).
-
You can set alarm thresholds for slow operations
-
The underlying connection uses I/O buffers
-
Communication between endpoints uses I/O multiplexing
teleport-server-peer
AB Testing 1: [Mac 4CPU 8GB] [single-process single-conn] teleport: QPS 37550
AB Testing 2: [Mac 4CPU 8GB] [single-process single-conn] teleport/socket: QPS 55419
2. The architecture
2.1 Name Description
-
Peer: indicates the communication endpoint, which can be a client or client
-
Session: Connects the Session, including push, pull, reply, and close operations
-
Context: Processes received or sent packets
-
Pull-launch: pulls data from the Peer
-
Pull-handle: processes and replies Pull requests of the Peer
-
Push-launch: pushes data to the Peer
-
Push-handle: Handles peer Push
-
Router: Indicates that the Handler registers routes
2.2 Execution Layers
Peer -> Connection -> Socket -> Session -> ContextCopy the code
2.3 the packet
HeaderLength | HeaderCodecId | Header | BodyLength | BodyCodecId | BodyCopy the code
Note:
-
HeaderLength: uint32, 4 bytes, big endian
-
BodyLength: uint32, 4 bytes, big endian
-
HeaderCodecId: uint8, 1 byte
-
BodyCodecId: uint8, 1 byte
type Packet struct {
// HeaderCodec header codec name
HeaderCodec string `json:"header_codec"`
// BodyCodec body codec name
BodyCodec string `json:"body_codec"`
// header content
Header *Header `json:"header"`
// body content
Body interface{} `json:"body"`
// header length
HeaderLength int64 `json:"header_length"`
// body length
BodyLength int64 `json:"body_length"`
// HeaderLength + BodyLength
Length int64 `json:"length"`
}Copy the code
2.4 header information
type Header struct {
// Packet id
Id string
// Service type
Type int32
// Service URI
Uri string
// Body encoding type
Gzip int32
// As reply, it indicates the service status code
StatusCode int32
// As reply, it indicates the service status text
Status string
}Copy the code
Open source projects
Project address: github.com/henrylee2cn… Licensing agreement: Apache2.0