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
07fbe698
Commit
07fbe698
authored
Aug 05, 2017
by
ginuerzh
Committed by
GitHub
Aug 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #126 from isofew/master
support obfs4 transport
parents
c72d6725
7f4b074d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
3 deletions
+139
-3
chain.go
chain.go
+1
-1
cmd/gost/main.go
cmd/gost/main.go
+1
-1
conn.go
conn.go
+6
-0
node.go
node.go
+7
-1
obfs4.go
obfs4.go
+114
-0
server.go
server.go
+10
-0
No files found.
chain.go
View file @
07fbe698
...
@@ -42,7 +42,7 @@ func (c *ProxyChain) AddProxyNode(node ...ProxyNode) {
...
@@ -42,7 +42,7 @@ func (c *ProxyChain) AddProxyNode(node ...ProxyNode) {
func
(
c
*
ProxyChain
)
AddProxyNodeString
(
snode
...
string
)
error
{
func
(
c
*
ProxyChain
)
AddProxyNodeString
(
snode
...
string
)
error
{
for
_
,
sn
:=
range
snode
{
for
_
,
sn
:=
range
snode
{
node
,
err
:=
ParseProxyNode
(
sn
)
node
,
err
:=
ParseProxyNode
(
sn
,
false
)
// isServeNode == false
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
cmd/gost/main.go
View file @
07fbe698
...
@@ -60,7 +60,7 @@ func main() {
...
@@ -60,7 +60,7 @@ func main() {
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
for
_
,
ns
:=
range
options
.
ServeNodes
{
for
_
,
ns
:=
range
options
.
ServeNodes
{
serverNode
,
err
:=
gost
.
ParseProxyNode
(
ns
)
serverNode
,
err
:=
gost
.
ParseProxyNode
(
ns
,
true
)
// isServeNode == true
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatal
(
err
)
glog
.
Fatal
(
err
)
}
}
...
...
conn.go
View file @
07fbe698
...
@@ -84,6 +84,12 @@ func (c *ProxyConn) handshake() error {
...
@@ -84,6 +84,12 @@ func (c *ProxyConn) handshake() error {
tlsUsed
=
true
tlsUsed
=
true
case
"kcp"
:
// kcp connection
case
"kcp"
:
// kcp connection
tlsUsed
=
true
tlsUsed
=
true
case
"obfs4"
:
conn
,
err
:=
c
.
Node
.
Obfs4ClientConn
(
c
.
conn
)
if
err
!=
nil
{
return
err
}
c
.
conn
=
conn
default
:
default
:
}
}
...
...
node.go
View file @
07fbe698
...
@@ -26,7 +26,7 @@ type ProxyNode struct {
...
@@ -26,7 +26,7 @@ type ProxyNode struct {
// The proxy node string pattern is [scheme://][user:pass@host]:port.
// The proxy node string pattern is [scheme://][user:pass@host]:port.
//
//
// Scheme can be devided into two parts by character '+', such as: http+tls.
// Scheme can be devided into two parts by character '+', such as: http+tls.
func
ParseProxyNode
(
s
string
)
(
node
ProxyNode
,
err
error
)
{
func
ParseProxyNode
(
s
string
,
isServeNode
bool
)
(
node
ProxyNode
,
err
error
)
{
if
!
strings
.
Contains
(
s
,
"://"
)
{
if
!
strings
.
Contains
(
s
,
"://"
)
{
s
=
"gost://"
+
s
s
=
"gost://"
+
s
}
}
...
@@ -79,6 +79,12 @@ func ParseProxyNode(s string) (node ProxyNode, err error) {
...
@@ -79,6 +79,12 @@ func ParseProxyNode(s string) (node ProxyNode, err error) {
node
.
Remote
=
strings
.
Trim
(
u
.
EscapedPath
(),
"/"
)
node
.
Remote
=
strings
.
Trim
(
u
.
EscapedPath
(),
"/"
)
case
"rtcp"
,
"rudp"
:
// started from v2.1, rtcp and rudp are for remote port forwarding
case
"rtcp"
,
"rudp"
:
// started from v2.1, rtcp and rudp are for remote port forwarding
node
.
Remote
=
strings
.
Trim
(
u
.
EscapedPath
(),
"/"
)
node
.
Remote
=
strings
.
Trim
(
u
.
EscapedPath
(),
"/"
)
case
"obfs4"
:
err
:=
node
.
Obfs4Init
(
isServeNode
)
if
err
!=
nil
{
glog
.
V
(
LDEBUG
)
.
Infoln
(
"obfs4 init failed"
,
err
)
return
node
,
err
}
default
:
default
:
node
.
Transport
=
""
node
.
Transport
=
""
}
}
...
...
obfs4.go
0 → 100644
View file @
07fbe698
// obfs4 connection wrappers
package
gost
import
(
"fmt"
"net"
"net/url"
"git.torproject.org/pluggable-transports/goptlib.git"
// package pt
"git.torproject.org/pluggable-transports/obfs4.git/transports/base"
"git.torproject.org/pluggable-transports/obfs4.git/transports/obfs4"
)
// Factories are stored per node since some arguments reside in them.
// For simplicity, c & s variables are packed together.
type
obfs4Context
struct
{
cf
base
.
ClientFactory
cargs
interface
{}
// type obfs4ClientArgs
sf
base
.
ServerFactory
sargs
*
pt
.
Args
}
var
obfs4Map
=
make
(
map
[
string
]
obfs4Context
)
func
(
node
*
ProxyNode
)
obfs4GetContext
()
(
obfs4Context
,
error
)
{
if
node
.
Transport
!=
"obfs4"
{
return
obfs4Context
{},
fmt
.
Errorf
(
"non-obfs4 node has no obfs4 context"
)
}
ctx
,
ok
:=
obfs4Map
[
node
.
Addr
]
if
!
ok
{
return
obfs4Context
{},
fmt
.
Errorf
(
"obfs4 context not inited"
)
}
return
ctx
,
nil
}
func
(
node
*
ProxyNode
)
Obfs4Init
(
isServeNode
bool
)
error
{
if
_
,
ok
:=
obfs4Map
[
node
.
Addr
];
ok
{
return
fmt
.
Errorf
(
"obfs4 context already inited"
)
}
t
:=
new
(
obfs4
.
Transport
)
stateDir
:=
node
.
values
.
Get
(
"state-dir"
)
if
stateDir
==
""
{
stateDir
=
"."
}
ptArgs
:=
pt
.
Args
(
node
.
values
)
if
!
isServeNode
{
cf
,
err
:=
t
.
ClientFactory
(
stateDir
)
if
err
!=
nil
{
return
err
}
cargs
,
err
:=
cf
.
ParseArgs
(
&
ptArgs
)
if
err
!=
nil
{
return
err
}
obfs4Map
[
node
.
Addr
]
=
obfs4Context
{
cf
:
cf
,
cargs
:
cargs
}
}
else
{
sf
,
err
:=
t
.
ServerFactory
(
stateDir
,
&
ptArgs
)
if
err
!=
nil
{
return
err
}
sargs
:=
sf
.
Args
()
obfs4Map
[
node
.
Addr
]
=
obfs4Context
{
sf
:
sf
,
sargs
:
sargs
}
fmt
.
Println
(
"[obfs4 server inited]"
,
node
.
Obfs4ServerURL
())
}
return
nil
}
func
(
node
*
ProxyNode
)
Obfs4ClientConn
(
conn
net
.
Conn
)
(
net
.
Conn
,
error
)
{
ctx
,
err
:=
node
.
obfs4GetContext
()
if
err
!=
nil
{
return
nil
,
err
}
pseudoDial
:=
func
(
a
,
b
string
)
(
net
.
Conn
,
error
)
{
return
conn
,
nil
}
return
ctx
.
cf
.
Dial
(
"tcp"
,
""
,
pseudoDial
,
ctx
.
cargs
)
}
func
(
node
*
ProxyNode
)
Obfs4ServerConn
(
conn
net
.
Conn
)
(
net
.
Conn
,
error
)
{
ctx
,
err
:=
node
.
obfs4GetContext
()
if
err
!=
nil
{
return
nil
,
err
}
return
ctx
.
sf
.
WrapConn
(
conn
)
}
func
(
node
*
ProxyNode
)
Obfs4ServerURL
()
string
{
ctx
,
err
:=
node
.
obfs4GetContext
()
if
err
!=
nil
{
return
""
}
values
:=
(
*
url
.
Values
)(
ctx
.
sargs
)
query
:=
values
.
Encode
()
return
fmt
.
Sprintf
(
"%s+%s://%s/?%s"
,
//obfs4-cert=%s&iat-mode=%s",
node
.
Protocol
,
node
.
Transport
,
node
.
Addr
,
query
,
)
}
server.go
View file @
07fbe698
...
@@ -141,6 +141,16 @@ func (s *ProxyServer) Serve() error {
...
@@ -141,6 +141,16 @@ func (s *ProxyServer) Serve() error {
setKeepAlive
(
conn
,
KeepAliveTime
)
setKeepAlive
(
conn
,
KeepAliveTime
)
if
node
.
Transport
==
"obfs4"
{
obfs4Conn
,
err
:=
node
.
Obfs4ServerConn
(
conn
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
err
)
conn
.
Close
()
continue
}
conn
=
obfs4Conn
}
go
s
.
handleConn
(
conn
)
go
s
.
handleConn
(
conn
)
}
}
}
}
...
...
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