Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
58161403
Commit
58161403
authored
Jan 02, 2022
by
Tsaiilin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redial update
parent
996c02dc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
23 deletions
+27
-23
client.go
client/client.go
+4
-2
event.go
client/event.go
+9
-6
eventlistener.go
client/eventlistener.go
+1
-1
getty.go
client/getty.go
+6
-6
httpping.go
infra/httpping.go
+0
-1
redail.go
infra/redail.go
+7
-7
No files found.
client/client.go
View file @
58161403
...
...
@@ -87,10 +87,12 @@ func (client *Client) check() {
continue
}
log
.
Run
()
.
Warnf
(
"Redial net check fail, redial..."
)
client
.
redial
.
RedialByCheck
(
cfg
)
if
client
.
session
!=
nil
{
client
.
session
.
Close
()
client
.
Redial
(
client
.
session
,
"check"
)
}
else
{
client
.
redial
.
RedialByCheck
(
cfg
)
}
}
})
}
client/event.go
View file @
58161403
...
...
@@ -15,6 +15,7 @@ import (
"virjar.com/majora-go/global"
"virjar.com/majora-go/log"
"virjar.com/majora-go/protocol"
"virjar.com/majora-go/safe"
"virjar.com/majora-go/trace"
)
...
...
@@ -69,17 +70,17 @@ func (client *Client) handleConnect(packet *protocol.MajoraPacket, session getty
ip
,
err
:=
client
.
dnsCache
.
Get
([]
byte
(
hostPort
[
0
]))
if
err
!=
nil
{
traceSession
.
Recorder
.
RecordEvent
(
trace
.
DnsResolveEvent
,
fmt
.
Sprintf
(
"Dns cache miss %s "
,
hostPort
[
0
]))
host
,
dnsErr
:=
net
.
LookupHost
(
hostPort
[
0
])
host
s
,
dnsErr
:=
net
.
LookupHost
(
hostPort
[
0
])
if
dnsErr
!=
nil
{
traceSession
.
Recorder
.
RecordErrorEvent
(
trace
.
DnsResolveEvent
,
fmt
.
Sprintf
(
"Resolve %s ip error"
,
hostPort
[
0
]),
dnsErr
)
client
.
closeVirtualConnection
(
session
,
packet
.
SerialNumber
)
return
}
err
:=
client
.
dnsCache
.
Set
([]
byte
(
hostPort
[
0
]),
[]
byte
(
host
[
0
]),
int
(
global
.
Config
.
DnsCacheDuration
.
Seconds
()))
err
:=
client
.
dnsCache
.
Set
([]
byte
(
hostPort
[
0
]),
[]
byte
(
host
s
[
0
]),
int
(
global
.
Config
.
DnsCacheDuration
.
Seconds
()))
if
err
!=
nil
{
traceSession
.
Recorder
.
RecordErrorEvent
(
trace
.
DnsResolveEvent
,
fmt
.
Sprintf
(
"Dns cache set error %s"
,
hostPort
[
0
]),
err
)
}
target
=
host
[
0
]
target
=
host
s
[
0
]
}
else
{
target
=
string
(
ip
)
}
...
...
@@ -119,9 +120,11 @@ func (client *Client) handleConnect(packet *protocol.MajoraPacket, session getty
client
.
closeVirtualConnection
(
session
,
packet
.
SerialNumber
)
return
}
else
{
safe
.
SageGo
(
func
()
{
client
.
handleUpStream
(
tcpConn
,
packet
,
session
)
})
log
.
Run
()
.
Debugf
(
"[handleConnect] %d->connect success to %s "
,
packet
.
SerialNumber
,
packet
.
Extra
)
traceSession
.
Recorder
.
RecordEvent
(
trace
.
ConnectEvent
,
fmt
.
Sprintf
(
"Replay natServer connect ready success (sn:%d)"
,
packet
.
SerialNumber
))
client
.
handleUpStream
(
tcpConn
,
packet
,
session
)
}
}
...
...
@@ -301,8 +304,8 @@ func (client *Client) OnClose(natSession getty.Session, upStreamSession net.Conn
log
.
Error
()
.
Errorf
(
"OnClose %+v"
,
err
)
}
}()
_
=
upStreamSession
.
Close
()
client
.
closeVirtualConnection
(
natSession
,
serialNumber
)
_
=
upStreamSession
.
Close
()
}
//closeVirtualConnection disconnect to server
...
...
@@ -327,9 +330,9 @@ func (client *Client) closeVirtualConnection(session getty.Session, serialNumber
session
.
IsClosed
(),
allCnt
,
sendCnt
,
serialNumber
),
err
)
session
.
Close
()
}
traceRecorder
.
RecordEvent
(
trace
.
DisconnectEvent
,
fmt
.
Sprintf
(
"Send disconnect to natServer success (sn:%d)"
,
serialNumber
))
client
.
connStore
.
Delete
(
serialNumber
)
client
.
sessionStore
.
Delete
(
serialNumber
)
traceRecorder
.
RecordEvent
(
trace
.
DisconnectEvent
,
fmt
.
Sprintf
(
"Send disconnect to natServer success (sn:%d)"
,
serialNumber
))
}
func
(
client
*
Client
)
CloseAll
(
session
getty
.
Session
)
{
...
...
client/eventlistener.go
View file @
58161403
...
...
@@ -42,7 +42,7 @@ func (m *MajoraEventListener) OnError(session getty.Session, err error) {
func
(
m
*
MajoraEventListener
)
OnCron
(
session
getty
.
Session
)
{
log
.
Run
()
.
Infof
(
"[OnCorn] Redial, session closed:%v"
,
session
.
IsClosed
())
m
.
client
.
Redial
(
session
)
m
.
client
.
Redial
(
session
,
"corn"
)
}
func
(
m
*
MajoraEventListener
)
OnMessage
(
session
getty
.
Session
,
input
interface
{})
{
...
...
client/getty.go
View file @
58161403
...
...
@@ -85,18 +85,18 @@ func InitialSession(session getty.Session, client *Client) (err error) {
return
nil
}
func
(
client
*
Client
)
Redial
(
session
getty
.
Session
)
{
log
.
Run
()
.
Infof
(
"[Redial
] start can redial ? %v"
,
client
.
config
.
Redial
.
Valid
())
func
(
client
*
Client
)
Redial
(
session
getty
.
Session
,
tag
string
)
{
log
.
Run
()
.
Infof
(
"[Redial
%s] start, can redial? %v"
,
tag
,
client
.
config
.
Redial
.
Valid
())
if
!
client
.
config
.
Redial
.
Valid
()
{
return
}
log
.
Run
()
.
Info
(
"[Redial] send offline message ..."
)
log
.
Run
()
.
Info
f
(
"[Redial %s] Send offline message"
,
tag
)
if
_
,
_
,
err
:=
session
.
WritePkg
(
OfflinePacket
,
0
);
err
!=
nil
{
log
.
Run
()
.
Errorf
(
"[Redial
] write offline to server error %s"
,
err
.
Error
())
log
.
Run
()
.
Errorf
(
"[Redial
%s] write offline to server error %s"
,
tag
,
err
.
Error
())
}
time
.
Sleep
(
client
.
config
.
Redial
.
WaitTime
)
log
.
Run
()
.
Info
(
"[Redial
] start close local session"
)
log
.
Run
()
.
Info
(
"[Redial
%s] start close local session"
,
tag
)
client
.
CloseAll
(
session
)
client
.
redial
.
Redial
(
client
.
config
)
client
.
redial
.
Redial
(
client
.
config
,
tag
)
session
.
Close
()
}
infra/httpping.go
View file @
58161403
...
...
@@ -31,7 +31,6 @@ const (
)
func
init
()
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
httpCli
=
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
TLSHandshakeTimeout
:
defTimeout
,
...
...
infra/redail.go
View file @
58161403
...
...
@@ -26,33 +26,33 @@ func NewPPPRedial() *PPPRedial {
}
}
func
(
p
*
PPPRedial
)
Redial
(
cfg
*
model
.
Configure
)
{
func
(
p
*
PPPRedial
)
Redial
(
cfg
*
model
.
Configure
,
tag
string
)
{
if
p
.
inRedialing
.
CAS
(
false
,
true
)
{
log
.
Run
()
.
Infof
(
"[
Redial] start"
)
log
.
Run
()
.
Infof
(
"[
PPPRedial %s] start"
,
tag
)
beforeIp
:=
GetPPP
()
retry
:=
0
defer
func
(
start
time
.
Time
)
{
newIp
:=
GetPPP
()
log
.
Run
()
.
Infof
(
"[
Redial
] retry %d, cost %v, ip change %s -> %s "
,
retry
,
time
.
Since
(
start
),
beforeIp
,
newIp
)
log
.
Run
()
.
Infof
(
"[
PPPRedial %s
] retry %d, cost %v, ip change %s -> %s "
,
tag
,
retry
,
time
.
Since
(
start
),
beforeIp
,
newIp
)
}(
time
.
Now
())
for
{
retry
++
status
:=
command
(
cfg
)
pingBaidu
:=
RandomPing
()
log
.
Run
()
.
Infof
(
"[
Redial] net check: %d->%v"
,
retry
,
pingBaidu
)
log
.
Run
()
.
Infof
(
"[
PPPRedial %s] net check: %d->%v"
,
tag
,
retry
,
pingBaidu
)
if
pingBaidu
&&
status
{
break
}
}
p
.
inRedialing
.
CAS
(
true
,
false
)
}
else
{
log
.
Run
()
.
Infof
(
"[
Redial] inRedialing ignore this"
)
log
.
Run
()
.
Infof
(
"[
PPPRedial %s] inRedialing ignore this"
,
tag
)
}
}
func
(
p
*
PPPRedial
)
RedialByCheck
(
cfg
*
model
.
Configure
)
{
p
.
Redial
(
cfg
)
p
.
Redial
(
cfg
,
"check"
)
}
func
command
(
cfg
*
model
.
Configure
)
bool
{
...
...
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