Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
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
Administrator
Titanium-Web-Proxy
Commits
b67ad5d5
Commit
b67ad5d5
authored
Dec 24, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small refactor
parent
f4afd161
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
50 deletions
+42
-50
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+1
-1
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+41
-49
No files found.
examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
b67ad5d5
...
@@ -91,7 +91,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -91,7 +91,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.AddEndPoint(transparentEndPoint);
//proxyServer.AddEndPoint(transparentEndPoint);
//proxyServer.UpStreamHttpProxy = new ExternalProxy("localhost", 8888);
//proxyServer.UpStreamHttpProxy = new ExternalProxy("localhost", 8888);
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("localhost", 8888
( }
);
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("localhost", 8888);
// SOCKS proxy
// SOCKS proxy
//proxyServer.UpStreamHttpProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 };
//proxyServer.UpStreamHttpProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 };
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
b67ad5d5
...
@@ -395,55 +395,9 @@ retry:
...
@@ -395,55 +395,9 @@ retry:
tcpServerSocket
.
SetSocketOption
(
SocketOptionLevel
.
Socket
,
SocketOptionName
.
ReuseAddress
,
true
);
tcpServerSocket
.
SetSocketOption
(
SocketOptionLevel
.
Socket
,
SocketOptionName
.
ReuseAddress
,
true
);
}
}
Task
connectTask
;
var
connectTask
=
socks
if
(
socks
)
?
ProxySocketConnectionTaskFactory
.
CreateTask
((
ProxySocket
.
ProxySocket
)
tcpServerSocket
,
ipAddress
,
port
)
{
:
SocketConnectionTaskFactory
.
CreateTask
(
tcpServerSocket
,
ipAddress
,
port
);
var
clientSocket
=
(
ProxySocket
.
ProxySocket
)
tcpServerSocket
;
IAsyncResult
BeginConnect
(
IPAddress
address
,
int
port
,
AsyncCallback
requestCallback
,
object
state
)
{
return
clientSocket
.
BeginConnect
(
address
,
port
,
requestCallback
,
state
);
}
void
EndConnect
(
IAsyncResult
asyncResult
)
{
var
s
=
clientSocket
;
if
(
s
==
null
)
{
// Dispose nulls out the client socket field.
throw
new
ObjectDisposedException
(
GetType
().
Name
);
}
s
.
EndConnect
(
asyncResult
);
}
connectTask
=
Task
.
Factory
.
FromAsync
(
BeginConnect
,
EndConnect
,
ipAddress
,
port
,
state
:
this
);
}
else
{
var
clientSocket
=
tcpServerSocket
;
IAsyncResult
BeginConnect
(
IPAddress
address
,
int
port
,
AsyncCallback
requestCallback
,
object
state
)
{
return
clientSocket
.
BeginConnect
(
address
,
port
,
requestCallback
,
state
);
}
void
EndConnect
(
IAsyncResult
asyncResult
)
{
var
s
=
clientSocket
;
if
(
s
==
null
)
{
// Dispose nulls out the client socket field.
throw
new
ObjectDisposedException
(
GetType
().
Name
);
}
s
.
EndConnect
(
asyncResult
);
}
connectTask
=
Task
.
Factory
.
FromAsync
(
BeginConnect
,
EndConnect
,
ipAddress
,
port
,
state
:
this
);
}
await
Task
.
WhenAny
(
connectTask
,
Task
.
Delay
(
proxyServer
.
ConnectTimeOutSeconds
*
1000
,
cancellationToken
));
await
Task
.
WhenAny
(
connectTask
,
Task
.
Delay
(
proxyServer
.
ConnectTimeOutSeconds
*
1000
,
cancellationToken
));
if
(!
connectTask
.
IsCompleted
||
!
tcpServerSocket
.
Connected
)
if
(!
connectTask
.
IsCompleted
||
!
tcpServerSocket
.
Connected
)
...
@@ -767,5 +721,43 @@ retry:
...
@@ -767,5 +721,43 @@ retry:
}
}
}
}
}
}
static
class
SocketConnectionTaskFactory
{
static
IAsyncResult
beginConnect
(
IPAddress
address
,
int
port
,
AsyncCallback
requestCallback
,
object
state
)
{
return
((
Socket
)
state
).
BeginConnect
(
address
,
port
,
requestCallback
,
state
);
}
static
void
endConnect
(
IAsyncResult
asyncResult
)
{
((
Socket
)
asyncResult
.
AsyncState
).
EndConnect
(
asyncResult
);
}
public
static
Task
CreateTask
(
Socket
socket
,
IPAddress
ipAddress
,
int
port
)
{
return
Task
.
Factory
.
FromAsync
(
beginConnect
,
endConnect
,
ipAddress
,
port
,
state
:
socket
);
}
}
static
class
ProxySocketConnectionTaskFactory
{
static
IAsyncResult
beginConnect
(
IPAddress
address
,
int
port
,
AsyncCallback
requestCallback
,
object
state
)
{
return
((
ProxySocket
.
ProxySocket
)
state
).
BeginConnect
(
address
,
port
,
requestCallback
,
state
);
}
static
void
endConnect
(
IAsyncResult
asyncResult
)
{
((
ProxySocket
.
ProxySocket
)
asyncResult
.
AsyncState
).
EndConnect
(
asyncResult
);
}
public
static
Task
CreateTask
(
ProxySocket
.
ProxySocket
socket
,
IPAddress
ipAddress
,
int
port
)
{
return
Task
.
Factory
.
FromAsync
(
beginConnect
,
endConnect
,
ipAddress
,
port
,
state
:
socket
);
}
}
}
}
}
}
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