Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
6f935fc3
Commit
6f935fc3
authored
Nov 15, 2017
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add retry mechanism for chain
parent
cd26bcb8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
6 deletions
+26
-6
chain.go
chain.go
+26
-6
No files found.
chain.go
View file @
6f935fc3
...
@@ -99,11 +99,21 @@ func (c *Chain) IsEmpty() bool {
...
@@ -99,11 +99,21 @@ func (c *Chain) IsEmpty() bool {
// Dial connects to the target address addr through the chain.
// Dial connects to the target address addr through the chain.
// If the chain is empty, it will use the net.Dial directly.
// If the chain is empty, it will use the net.Dial directly.
func
(
c
*
Chain
)
Dial
(
addr
string
)
(
net
.
Conn
,
error
)
{
func
(
c
*
Chain
)
Dial
(
addr
string
)
(
conn
net
.
Conn
,
err
error
)
{
if
c
.
IsEmpty
()
{
if
c
.
IsEmpty
()
{
return
net
.
DialTimeout
(
"tcp"
,
addr
,
DialTimeout
)
return
net
.
DialTimeout
(
"tcp"
,
addr
,
DialTimeout
)
}
}
for
i
:=
0
;
i
<
c
.
Retries
+
1
;
i
++
{
conn
,
err
=
c
.
dial
(
addr
)
if
err
==
nil
{
break
}
}
return
}
func
(
c
*
Chain
)
dial
(
addr
string
)
(
net
.
Conn
,
error
)
{
route
,
err
:=
c
.
selectRoute
()
route
,
err
:=
c
.
selectRoute
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -125,11 +135,19 @@ func (c *Chain) Dial(addr string) (net.Conn, error) {
...
@@ -125,11 +135,19 @@ func (c *Chain) Dial(addr string) (net.Conn, error) {
// Conn obtains a handshaked connection to the last node of the chain.
// Conn obtains a handshaked connection to the last node of the chain.
// If the chain is empty, it returns an ErrEmptyChain error.
// If the chain is empty, it returns an ErrEmptyChain error.
func
(
c
*
Chain
)
Conn
()
(
conn
net
.
Conn
,
err
error
)
{
func
(
c
*
Chain
)
Conn
()
(
conn
net
.
Conn
,
err
error
)
{
route
,
err
:=
c
.
selectRoute
()
for
i
:=
0
;
i
<
c
.
Retries
+
1
;
i
++
{
var
route
*
Chain
route
,
err
=
c
.
selectRoute
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
continue
}
}
conn
,
err
=
route
.
getConn
()
conn
,
err
=
route
.
getConn
()
if
err
!=
nil
{
continue
}
break
}
return
return
}
}
...
@@ -205,6 +223,8 @@ func (c *Chain) selectRoute() (route *Chain, err error) {
...
@@ -205,6 +223,8 @@ func (c *Chain) selectRoute() (route *Chain, err error) {
route
.
AddNode
(
node
)
route
.
AddNode
(
node
)
}
}
if
Debug
{
log
.
Log
(
"select route:"
,
buf
.
String
())
log
.
Log
(
"select route:"
,
buf
.
String
())
}
return
return
}
}
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