Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
shapeshifter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leap
shapeshifter
Commits
66fa9972
Unverified
Commit
66fa9972
authored
5 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Add error handling support
parent
e4fbb2f0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
shapeshifter.go
+30
-3
30 additions, 3 deletions
shapeshifter.go
with
30 additions
and
3 deletions
shapeshifter.go
+
30
−
3
View file @
66fa9972
...
@@ -16,6 +16,7 @@ type ShapeShifter struct {
...
@@ -16,6 +16,7 @@ type ShapeShifter struct {
Target
string
// remote ip:port obfs4 server
Target
string
// remote ip:port obfs4 server
SocksAddr
string
// -proxylistenaddr in shapeshifter-dispatcher
SocksAddr
string
// -proxylistenaddr in shapeshifter-dispatcher
ln
net
.
Listener
ln
net
.
Listener
errChan
chan
error
}
}
func
(
ss
*
ShapeShifter
)
Open
()
error
{
func
(
ss
*
ShapeShifter
)
Open
()
error
{
...
@@ -40,6 +41,20 @@ func (ss *ShapeShifter) Close() error {
...
@@ -40,6 +41,20 @@ func (ss *ShapeShifter) Close() error {
return
nil
return
nil
}
}
func
(
ss
*
ShapeShifter
)
GetErrorChannel
()
chan
error
{
if
ss
.
errChan
==
nil
{
ss
.
errChan
=
make
(
chan
error
,
2
)
}
return
ss
.
errChan
}
func
(
ss
*
ShapeShifter
)
GetLastError
()
error
{
if
ss
.
errChan
==
nil
{
ss
.
errChan
=
make
(
chan
error
,
2
)
}
return
<-
ss
.
errChan
}
func
(
ss
ShapeShifter
)
clientAcceptLoop
()
error
{
func
(
ss
ShapeShifter
)
clientAcceptLoop
()
error
{
for
{
for
{
conn
,
err
:=
ss
.
ln
.
Accept
()
conn
,
err
:=
ss
.
ln
.
Accept
()
...
@@ -47,6 +62,7 @@ func (ss ShapeShifter) clientAcceptLoop() error {
...
@@ -47,6 +62,7 @@ func (ss ShapeShifter) clientAcceptLoop() error {
if
e
,
ok
:=
err
.
(
net
.
Error
);
ok
&&
!
e
.
Temporary
()
{
if
e
,
ok
:=
err
.
(
net
.
Error
);
ok
&&
!
e
.
Temporary
()
{
return
err
return
err
}
}
ss
.
sendError
(
"Error accepting connection: %v"
,
err
)
continue
continue
}
}
go
ss
.
clientHandler
(
conn
)
go
ss
.
clientHandler
(
conn
)
...
@@ -59,18 +75,18 @@ func (ss ShapeShifter) clientHandler(conn net.Conn) {
...
@@ -59,18 +75,18 @@ func (ss ShapeShifter) clientHandler(conn net.Conn) {
transport
:=
obfs4
.
NewObfs4Client
(
ss
.
Cert
,
ss
.
IatMode
)
transport
:=
obfs4
.
NewObfs4Client
(
ss
.
Cert
,
ss
.
IatMode
)
remote
,
err
:=
transport
.
Dial
(
ss
.
Target
)
remote
,
err
:=
transport
.
Dial
(
ss
.
Target
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"outgoing connection failed %s: %v"
,
ss
.
Target
,
err
)
ss
.
sendError
(
"outgoing connection failed %s: %v"
,
ss
.
Target
,
err
)
return
return
}
}
if
remote
==
nil
{
if
remote
==
nil
{
log
.
Printf
(
"outgoing connection failed %s"
,
ss
.
Target
)
ss
.
sendError
(
"outgoing connection failed %s"
,
ss
.
Target
)
return
return
}
}
defer
remote
.
Close
()
defer
remote
.
Close
()
err
=
copyLoop
(
conn
,
remote
)
err
=
copyLoop
(
conn
,
remote
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"%s - closed connection: %v"
,
ss
.
Target
,
err
)
ss
.
sendError
(
"%s - closed connection: %v"
,
ss
.
Target
,
err
)
}
else
{
}
else
{
log
.
Printf
(
"%s - closed connection"
,
ss
.
Target
)
log
.
Printf
(
"%s - closed connection"
,
ss
.
Target
)
}
}
...
@@ -121,3 +137,14 @@ func (ss *ShapeShifter) checkOptions() error {
...
@@ -121,3 +137,14 @@ func (ss *ShapeShifter) checkOptions() error {
}
}
return
nil
return
nil
}
}
func
(
ss
*
ShapeShifter
)
sendError
(
format
string
,
a
...
interface
{})
{
if
ss
.
errChan
==
nil
{
ss
.
errChan
=
make
(
chan
error
,
2
)
}
select
{
case
ss
.
errChan
<-
fmt
.
Errorf
(
format
,
a
...
)
:
default
:
log
.
Printf
(
format
,
a
...
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment