Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
majora-go
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
majora
majora-go
Commits
7a10af48
Commit
7a10af48
authored
Oct 30, 2021
by
wei.xuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update timeout
parent
6a967689
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
7 deletions
+11
-7
event.go
client/event.go
+5
-3
eventlistener.go
client/eventlistener.go
+6
-2
getty.go
client/getty.go
+0
-2
No files found.
client/event.go
View file @
7a10af48
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"fmt"
"fmt"
"net"
"net"
"strings"
"strings"
"sync"
"time"
"time"
"github.com/adamweixuan/getty"
"github.com/adamweixuan/getty"
...
@@ -21,9 +22,9 @@ var (
...
@@ -21,9 +22,9 @@ var (
func
(
client
*
Client
)
handleHeartbeat
(
session
getty
.
Session
)
{
func
(
client
*
Client
)
handleHeartbeat
(
session
getty
.
Session
)
{
go
func
()
{
go
func
()
{
if
_
,
_
,
err
:=
session
.
WritePkg
(
HeartbeatPacket
,
time
.
Second
*
3
);
err
!=
nil
{
if
_
,
_
,
err
:=
session
.
WritePkg
(
HeartbeatPacket
,
time
.
Second
*
3
);
err
!=
nil
{
getty
.
GetLogger
()
.
Errorf
(
"handleHeartbeat error %+v %v
->%v"
,
err
,
session
.
IsClosed
(),
session
.
GetActive
())
getty
.
GetLogger
()
.
Errorf
(
"handleHeartbeat error %+v %v
"
,
err
,
session
.
IsClosed
())
}
else
{
}
else
{
getty
.
GetLogger
()
.
Infof
(
"handleHeartbeat success %v
->%v"
,
session
.
IsClosed
(),
session
.
GetActive
())
getty
.
GetLogger
()
.
Infof
(
"handleHeartbeat success %v
"
,
session
.
IsClosed
())
}
}
}()
}()
}
}
...
@@ -188,8 +189,9 @@ func (client *Client) CloseAll(session getty.Session) {
...
@@ -188,8 +189,9 @@ func (client *Client) CloseAll(session getty.Session) {
client
.
connStore
.
Range
(
func
(
key
,
value
interface
{})
bool
{
client
.
connStore
.
Range
(
func
(
key
,
value
interface
{})
bool
{
serialNumber
:=
key
.
(
int64
)
serialNumber
:=
key
.
(
int64
)
conn
,
_
:=
value
.
(
net
.
Conn
)
conn
,
_
:=
value
.
(
net
.
Conn
)
getty
.
GetLogger
()
.
Infof
(
"close serialNumber -> %d"
,
serialNumber
)
getty
.
GetLogger
()
.
Infof
(
"
[CloseAll]
close serialNumber -> %d"
,
serialNumber
)
client
.
OnClose
(
session
,
conn
,
serialNumber
)
client
.
OnClose
(
session
,
conn
,
serialNumber
)
return
true
return
true
})
})
client
.
connStore
=
sync
.
Map
{}
}
}
client/eventlistener.go
View file @
7a10af48
package
client
package
client
import
(
import
(
"errors"
"runtime"
"runtime"
"time"
"time"
...
@@ -14,7 +15,7 @@ type MajoraEventListener struct {
...
@@ -14,7 +15,7 @@ type MajoraEventListener struct {
}
}
func
(
m
*
MajoraEventListener
)
OnOpen
(
session
getty
.
Session
)
error
{
func
(
m
*
MajoraEventListener
)
OnOpen
(
session
getty
.
Session
)
error
{
getty
.
GetLogger
()
.
Info
(
"==================OnOpen=================="
)
getty
.
GetLogger
()
.
Info
f
(
"connect to nathost %s success ..."
,
m
.
client
.
config
.
TunnelAddr
)
packet
:=
protocol
.
TypeRegister
.
CreatePacket
()
packet
:=
protocol
.
TypeRegister
.
CreatePacket
()
packet
.
Extra
=
m
.
client
.
config
.
ClientID
packet
.
Extra
=
m
.
client
.
config
.
ClientID
extraMap
:=
make
(
map
[
string
]
string
,
1
)
extraMap
:=
make
(
map
[
string
]
string
,
1
)
...
@@ -35,8 +36,11 @@ func (m *MajoraEventListener) OnClose(session getty.Session) {
...
@@ -35,8 +36,11 @@ func (m *MajoraEventListener) OnClose(session getty.Session) {
func
(
m
*
MajoraEventListener
)
OnError
(
session
getty
.
Session
,
err
error
)
{
func
(
m
*
MajoraEventListener
)
OnError
(
session
getty
.
Session
,
err
error
)
{
getty
.
GetLogger
()
.
Errorf
(
"OnError %s"
,
err
.
Error
())
getty
.
GetLogger
()
.
Errorf
(
"OnError %s"
,
err
.
Error
())
if
errors
.
Is
(
err
,
common
.
ErrInvalidMagic
)
{
session
.
Close
()
}
m
.
client
.
CloseAll
(
session
)
m
.
client
.
CloseAll
(
session
)
session
.
Close
()
}
}
func
(
m
*
MajoraEventListener
)
OnCron
(
session
getty
.
Session
)
{
func
(
m
*
MajoraEventListener
)
OnCron
(
session
getty
.
Session
)
{
...
...
client/getty.go
View file @
7a10af48
...
@@ -29,7 +29,6 @@ func (client *Client) connect() {
...
@@ -29,7 +29,6 @@ func (client *Client) connect() {
getty
.
WithClientTaskPool
(
taskPool
))
getty
.
WithClientTaskPool
(
taskPool
))
gettyCli
.
RunEventLoop
(
NewClientSession
(
client
))
gettyCli
.
RunEventLoop
(
NewClientSession
(
client
))
client
.
natTunnel
=
gettyCli
client
.
natTunnel
=
gettyCli
getty
.
GetLogger
()
.
Infof
(
"connect to nathost %s success ..."
,
hostPort
)
}
}
func
NewClientSession
(
client
*
Client
)
func
(
getty
.
Session
)
error
{
func
NewClientSession
(
client
*
Client
)
func
(
getty
.
Session
)
error
{
...
@@ -81,7 +80,6 @@ func InitialSession(session getty.Session, client *Client) (err error) {
...
@@ -81,7 +80,6 @@ func InitialSession(session getty.Session, client *Client) (err error) {
func
(
client
*
Client
)
Redial
(
session
getty
.
Session
)
{
func
(
client
*
Client
)
Redial
(
session
getty
.
Session
)
{
if
!
client
.
config
.
Redial
.
Valid
()
{
if
!
client
.
config
.
Redial
.
Valid
()
{
getty
.
GetLogger
()
.
Warnf
(
"Redial invalid"
)
return
return
}
}
client
.
CloseAll
(
session
)
client
.
CloseAll
(
session
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment