Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
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
wei.xuan
getty
Commits
b889df9d
Commit
b889df9d
authored
Oct 29, 2021
by
wei.xuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:bind local ip
parent
3db78c9b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
27 deletions
+22
-27
client.go
client.go
+17
-10
connection.go
connection.go
+0
-2
options.go
options.go
+4
-2
server.go
server.go
+0
-5
session.go
session.go
+1
-6
tls.go
tls.go
+0
-2
No files found.
client.go
View file @
b889df9d
...
...
@@ -27,9 +27,7 @@ import (
"sync"
"sync/atomic"
"time"
)
import
(
"github.com/adamweixuan/gostnops/bytes"
"github.com/adamweixuan/gostnops/net"
gxsync
"github.com/adamweixuan/gostnops/sync"
...
...
@@ -102,12 +100,12 @@ func newClient(t EndPointType, opts ...ClientOption) *client {
// NewTCPClient builds a tcp client.
func
NewTCPClient
(
opts
...
ClientOption
)
Client
{
return
newClient
(
T
CP_CLIENT
,
opts
...
)
return
newClient
(
T
cpClient
,
opts
...
)
}
// NewUDPClient builds a connected udp client
func
NewUDPClient
(
opts
...
ClientOption
)
Client
{
return
newClient
(
U
DP_CLIENT
,
opts
...
)
return
newClient
(
U
dpClient
,
opts
...
)
}
func
(
c
*
client
)
ID
()
EndPointID
{
...
...
@@ -134,18 +132,27 @@ func (c *client) dialTCP() Session {
conn
,
err
=
tls
.
DialWithDialer
(
d
,
"tcp"
,
c
.
addr
,
sslConfig
)
}
}
else
{
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
c
.
addr
,
connectTimeout
)
if
c
.
laddr
!=
nil
{
dialer
:=
net
.
Dialer
{
Timeout
:
connectTimeout
,
LocalAddr
:
c
.
laddr
,
}
conn
,
err
=
dialer
.
Dial
(
"tcp"
,
c
.
addr
)
}
else
{
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
c
.
addr
,
connectTimeout
)
}
}
if
err
==
nil
&&
gxnet
.
IsSameAddr
(
conn
.
RemoteAddr
(),
conn
.
LocalAddr
())
{
conn
.
Close
()
err
=
errSelfConnect
}
if
err
==
nil
{
log
.
Infof
(
"net.DialSuccess(laddr:%s->addr:%s)"
,
c
.
laddr
,
c
.
addr
)
return
newTCPSession
(
conn
,
c
)
}
log
.
Infof
(
"net.DialTimeout(addr:%s, timeout:%v) = error:%+v"
,
c
.
addr
,
connectTimeout
,
perrors
.
WithStack
(
err
)
)
<-
gxtime
.
After
(
connectInterval
)
log
.
Warnf
(
"net.DialTimeout(addr:%s, timeout:%v) = error:%+v"
,
c
.
addr
,
connectTimeout
,
err
)
<-
gxtime
.
After
(
time
.
Second
)
}
}
...
...
@@ -316,11 +323,11 @@ func (c *client) dialWSS() Session {
func
(
c
*
client
)
dial
()
Session
{
switch
c
.
endPointType
{
case
T
CP_CLIENT
:
case
T
cpClient
:
return
c
.
dialTCP
()
case
U
DP_CLIENT
:
case
U
dpClient
:
return
c
.
dialUDP
()
case
W
S_CLIENT
:
case
W
sClient
:
return
c
.
dialWS
()
case
WSS_CLIENT
:
return
c
.
dialWSS
()
...
...
connection.go
View file @
b889df9d
...
...
@@ -25,9 +25,7 @@ import (
"net"
"sync"
"time"
)
import
(
"github.com/golang/snappy"
"github.com/gorilla/websocket"
perrors
"github.com/pkg/errors"
...
...
options.go
View file @
b889df9d
...
...
@@ -18,6 +18,8 @@
package
getty
import
(
"net"
gxsync
"github.com/adamweixuan/gostnops/sync"
)
...
...
@@ -101,7 +103,7 @@ type ClientOption func(*ClientOptions)
type
ClientOptions
struct
{
addr
string
laddr
string
// local addr
laddr
net
.
Addr
// local addr
number
int
reconnectInterval
int
// reConnect Interval
...
...
@@ -125,7 +127,7 @@ func WithServerAddress(addr string) ClientOption {
}
// WithLocalAddressClient @addr is server address.
func
WithLocalAddressClient
(
addr
string
)
ClientOption
{
func
WithLocalAddressClient
(
addr
net
.
Addr
)
ClientOption
{
return
func
(
o
*
ClientOptions
)
{
o
.
laddr
=
addr
}
...
...
server.go
View file @
b889df9d
...
...
@@ -28,17 +28,12 @@ import (
"strings"
"sync"
"time"
)
import
(
gxnet
"github.com/adamweixuan/gostnops/net"
gxsync
"github.com/adamweixuan/gostnops/sync"
gxtime
"github.com/adamweixuan/gostnops/time"
"github.com/gorilla/websocket"
perrors
"github.com/pkg/errors"
uatomic
"go.uber.org/atomic"
)
...
...
session.go
View file @
b889df9d
...
...
@@ -26,23 +26,18 @@ import (
"runtime"
"sync"
"time"
)
import
(
gxbytes
"github.com/adamweixuan/gostnops/bytes"
gxcontext
"github.com/adamweixuan/gostnops/context"
gxtime
"github.com/adamweixuan/gostnops/time"
"github.com/gorilla/websocket"
perrors
"github.com/pkg/errors"
uatomic
"go.uber.org/atomic"
)
const
(
maxReadBufLen
=
4
*
1024
netIOTimeout
=
1e9
// 1
s
netIOTimeout
=
1e9
*
10
// 10
s
period
=
60
*
1e9
// 1 minute
pendingDuration
=
3e9
// MaxWheelTimeSpan 900s, 15 minute
...
...
tls.go
View file @
b889df9d
...
...
@@ -22,9 +22,7 @@ import (
"crypto/x509"
"fmt"
"io/ioutil"
)
import
(
perrors
"github.com/pkg/errors"
)
...
...
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