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
f89062a8
Commit
f89062a8
authored
Jun 15, 2019
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #364
parent
466d2fef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
+37
-9
cmd/gost/peer.go
cmd/gost/peer.go
+7
-4
cmd/gost/route.go
cmd/gost/route.go
+7
-4
selector.go
selector.go
+23
-1
No files found.
cmd/gost/peer.go
View file @
f89062a8
...
@@ -57,10 +57,13 @@ func (cfg *peerConfig) Reload(r io.Reader) error {
...
@@ -57,10 +57,13 @@ func (cfg *peerConfig) Reload(r io.Reader) error {
group
:=
cfg
.
group
group
:=
cfg
.
group
group
.
SetSelector
(
group
.
SetSelector
(
nil
,
nil
,
gost
.
WithFilter
(
&
gost
.
FailFilter
{
gost
.
WithFilter
(
MaxFails
:
cfg
.
MaxFails
,
&
gost
.
FailFilter
{
FailTimeout
:
cfg
.
FailTimeout
,
MaxFails
:
cfg
.
MaxFails
,
}),
FailTimeout
:
cfg
.
FailTimeout
,
},
&
gost
.
InvalidFilter
{},
),
gost
.
WithStrategy
(
gost
.
NewStrategy
(
cfg
.
Strategy
)),
gost
.
WithStrategy
(
gost
.
NewStrategy
(
cfg
.
Strategy
)),
)
)
...
...
cmd/gost/route.go
View file @
f89062a8
...
@@ -52,10 +52,13 @@ func (r *route) parseChain() (*gost.Chain, error) {
...
@@ -52,10 +52,13 @@ func (r *route) parseChain() (*gost.Chain, error) {
ngroup
.
AddNode
(
nodes
...
)
ngroup
.
AddNode
(
nodes
...
)
ngroup
.
SetSelector
(
nil
,
ngroup
.
SetSelector
(
nil
,
gost
.
WithFilter
(
&
gost
.
FailFilter
{
gost
.
WithFilter
(
MaxFails
:
defaultMaxFails
,
&
gost
.
FailFilter
{
FailTimeout
:
defaultFailTimeout
,
MaxFails
:
defaultMaxFails
,
}),
FailTimeout
:
defaultFailTimeout
,
},
&
gost
.
InvalidFilter
{},
),
gost
.
WithStrategy
(
gost
.
NewStrategy
(
nodes
[
0
]
.
Get
(
"strategy"
))),
gost
.
WithStrategy
(
gost
.
NewStrategy
(
nodes
[
0
]
.
Get
(
"strategy"
))),
)
)
...
...
selector.go
View file @
f89062a8
...
@@ -3,6 +3,8 @@ package gost
...
@@ -3,6 +3,8 @@ package gost
import
(
import
(
"errors"
"errors"
"math/rand"
"math/rand"
"net"
"strconv"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"time"
"time"
...
@@ -167,7 +169,7 @@ type FailFilter struct {
...
@@ -167,7 +169,7 @@ type FailFilter struct {
FailTimeout
time
.
Duration
FailTimeout
time
.
Duration
}
}
// Filter filters nodes.
// Filter filters
dead
nodes.
func
(
f
*
FailFilter
)
Filter
(
nodes
[]
Node
)
[]
Node
{
func
(
f
*
FailFilter
)
Filter
(
nodes
[]
Node
)
[]
Node
{
if
len
(
nodes
)
<=
1
||
f
.
MaxFails
<=
0
{
if
len
(
nodes
)
<=
1
||
f
.
MaxFails
<=
0
{
return
nodes
return
nodes
...
@@ -188,6 +190,26 @@ func (f *FailFilter) String() string {
...
@@ -188,6 +190,26 @@ func (f *FailFilter) String() string {
return
"fail"
return
"fail"
}
}
// InvalidFilter filters the invalid node.
// A node is invalid if its port is invalid (negative or zero value).
type
InvalidFilter
struct
{}
// Filter filters invalid nodes.
func
(
f
*
InvalidFilter
)
Filter
(
nodes
[]
Node
)
[]
Node
{
nl
:=
[]
Node
{}
for
i
:=
range
nodes
{
_
,
sport
,
_
:=
net
.
SplitHostPort
(
nodes
[
i
]
.
Addr
)
if
port
,
_
:=
strconv
.
Atoi
(
sport
);
port
>
0
{
nl
=
append
(
nl
,
nodes
[
i
])
}
}
return
nl
}
func
(
f
*
InvalidFilter
)
String
()
string
{
return
"invalid"
}
type
failMarker
struct
{
type
failMarker
struct
{
failTime
int64
failTime
int64
failCount
uint32
failCount
uint32
...
...
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