Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
82790582
Commit
82790582
authored
4 years ago
by
haohongfan
Browse files
Options
Downloads
Patches
Plain Diff
feat: add some comment
parent
d3667059
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
remoting/getty/config.go
+8
-10
8 additions, 10 deletions
remoting/getty/config.go
remoting/getty/readwriter.go
+9
-3
9 additions, 3 deletions
remoting/getty/readwriter.go
with
17 additions
and
13 deletions
remoting/getty/config.go
+
8
−
10
View file @
82790582
...
...
@@ -30,7 +30,7 @@ import (
)
type
(
// GettySessionParam
...
// GettySessionParam
is session configuration for getty
GettySessionParam
struct
{
CompressEncoding
bool
`default:"false" yaml:"compress_encoding" json:"compress_encoding,omitempty"`
TcpNoDelay
bool
`default:"true" yaml:"tcp_no_delay" json:"tcp_no_delay,omitempty"`
...
...
@@ -50,8 +50,7 @@ type (
SessionName
string
`default:"rpc" yaml:"session_name" json:"session_name,omitempty"`
}
// ServerConfig
//Config holds supported types by the multiconfig package
// ServerConfig holds supported types by the multiconfig package
ServerConfig
struct
{
SSLEnabled
bool
...
...
@@ -69,8 +68,7 @@ type (
GettySessionParam
GettySessionParam
`required:"true" yaml:"getty_session_param" json:"getty_session_param,omitempty"`
}
// ClientConfig
//Config holds supported types by the multiconfig package
// ClientConfig holds supported types by the multiconfig package
ClientConfig
struct
{
ReconnectInterval
int
`default:"0" yaml:"reconnect_interval" json:"reconnect_interval,omitempty"`
...
...
@@ -99,7 +97,7 @@ type (
}
)
// GetDefaultClientConfig
...
// GetDefaultClientConfig
gets client default configuration
func
GetDefaultClientConfig
()
ClientConfig
{
return
ClientConfig
{
ReconnectInterval
:
0
,
...
...
@@ -127,7 +125,7 @@ func GetDefaultClientConfig() ClientConfig {
}}
}
// GetDefaultServerConfig
...
// GetDefaultServerConfig
gets server default configuration
func
GetDefaultServerConfig
()
ServerConfig
{
return
ServerConfig
{
SessionTimeout
:
"180s"
,
...
...
@@ -152,7 +150,7 @@ func GetDefaultServerConfig() ServerConfig {
}
}
// CheckValidity
...
// CheckValidity
confirm getty sessian params
func
(
c
*
GettySessionParam
)
CheckValidity
()
error
{
var
err
error
...
...
@@ -175,7 +173,7 @@ func (c *GettySessionParam) CheckValidity() error {
return
nil
}
// CheckValidity
..
.
// CheckValidity
confirm client params
.
func
(
c
*
ClientConfig
)
CheckValidity
()
error
{
var
err
error
...
...
@@ -197,7 +195,7 @@ func (c *ClientConfig) CheckValidity() error {
return
perrors
.
WithStack
(
c
.
GettySessionParam
.
CheckValidity
())
}
// CheckValidity
...
// CheckValidity
confirm server params
func
(
c
*
ServerConfig
)
CheckValidity
()
error
{
var
err
error
...
...
This diff is collapsed.
Click to expand it.
remoting/getty/readwriter.go
+
9
−
3
View file @
82790582
...
...
@@ -36,16 +36,18 @@ import (
// RpcClientPackageHandler
////////////////////////////////////////////
// RpcClientPackageHandler
...
// RpcClientPackageHandler
Read data from server and Write data to server
type
RpcClientPackageHandler
struct
{
client
*
Client
}
// NewRpcClientPackageHandler
...
// NewRpcClientPackageHandler
create a RpcClientPackageHandler
func
NewRpcClientPackageHandler
(
client
*
Client
)
*
RpcClientPackageHandler
{
return
&
RpcClientPackageHandler
{
client
:
client
}
}
// Read data from server. if the package size from server is larger than 4096 byte, server will read 4096 byte
// and send to client each time. the Read can assemble it.
func
(
p
*
RpcClientPackageHandler
)
Read
(
ss
getty
.
Session
,
data
[]
byte
)
(
interface
{},
int
,
error
)
{
resp
,
length
,
err
:=
(
p
.
client
.
codec
)
.
Decode
(
data
)
//err := pkg.Unmarshal(buf, p.client)
...
...
@@ -63,6 +65,7 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface
return
resp
,
length
,
nil
}
// Write send the data to server
func
(
p
*
RpcClientPackageHandler
)
Write
(
ss
getty
.
Session
,
pkg
interface
{})
([]
byte
,
error
)
{
req
,
ok
:=
pkg
.
(
*
remoting
.
Request
)
if
!
ok
{
...
...
@@ -87,7 +90,7 @@ func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) ([]by
// rpcServerPkgHandler = &RpcServerPackageHandler{}
//)
// RpcServerPackageHandler
...
// RpcServerPackageHandler
Read data from client and Write data to client
type
RpcServerPackageHandler
struct
{
server
*
Server
}
...
...
@@ -96,6 +99,8 @@ func NewRpcServerPackageHandler(server *Server) *RpcServerPackageHandler {
return
&
RpcServerPackageHandler
{
server
:
server
}
}
// Read data from client. if the package size from client is larger than 4096 byte, client will read 4096 byte
// and send to client each time. the Read can assemble it.
func
(
p
*
RpcServerPackageHandler
)
Read
(
ss
getty
.
Session
,
data
[]
byte
)
(
interface
{},
int
,
error
)
{
req
,
length
,
err
:=
(
p
.
server
.
codec
)
.
Decode
(
data
)
//resp,len, err := (*p.).DecodeResponse(buf)
...
...
@@ -113,6 +118,7 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
return
req
,
length
,
err
}
// Write send the data to client
func
(
p
*
RpcServerPackageHandler
)
Write
(
ss
getty
.
Session
,
pkg
interface
{})
([]
byte
,
error
)
{
res
,
ok
:=
pkg
.
(
*
remoting
.
Response
)
if
!
ok
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment