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
84d4effc
Commit
84d4effc
authored
Jun 26, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Connection count changed events
parent
02aa8d29
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
10 deletions
+78
-10
MainWindow.xaml
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml
+13
-3
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+20
-0
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+1
-1
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+41
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+2
-2
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+1
-1
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml
View file @
84d4effc
...
@@ -13,8 +13,12 @@
...
@@ -13,8 +13,12 @@
<ColumnDefinition Width="3" />
<ColumnDefinition Width="3" />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" />
<Grid.RowDefinitions>
<ListView Grid.Column="0" HorizontalAlignment="Stretch" ItemsSource="{Binding Sessions}" SelectedItem="{Binding SelectedSession}"
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<GridSplitter Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" />
<ListView Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" ItemsSource="{Binding Sessions}" SelectedItem="{Binding SelectedSession}"
KeyDown="ListViewSessions_OnKeyDown">
KeyDown="ListViewSessions_OnKeyDown">
<ListView.View>
<ListView.View>
<GridView>
<GridView>
...
@@ -29,7 +33,7 @@
...
@@ -29,7 +33,7 @@
</GridView>
</GridView>
</ListView.View>
</ListView.View>
</ListView>
</ListView>
<TabControl Grid.Column="2">
<TabControl Grid.Column="2"
Grid.Row="0"
>
<TabItem Header="Session">
<TabItem Header="Session">
<Grid Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<Grid.RowDefinitions>
...
@@ -41,5 +45,11 @@
...
@@ -41,5 +45,11 @@
</Grid>
</Grid>
</TabItem>
</TabItem>
</TabControl>
</TabControl>
<StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
<TextBlock Text="ClientConnectionCount:" />
<TextBlock Text="{Binding ClientConnectionCount}" Margin="10,0,20,0" />
<TextBlock Text="ServerConnectionCount:" />
<TextBlock Text="{Binding ServerConnectionCount}" Margin="10,0,20,0" />
</StackPanel>
</Grid>
</Grid>
</Window>
</Window>
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
84d4effc
...
@@ -44,6 +44,24 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -44,6 +44,24 @@ namespace Titanium.Web.Proxy.Examples.Wpf
}
}
}
}
public
static
readonly
DependencyProperty
ClientConnectionCountProperty
=
DependencyProperty
.
Register
(
nameof
(
ClientConnectionCount
),
typeof
(
int
),
typeof
(
MainWindow
),
new
PropertyMetadata
(
default
(
int
)));
public
int
ClientConnectionCount
{
get
{
return
(
int
)
GetValue
(
ClientConnectionCountProperty
);
}
set
{
SetValue
(
ClientConnectionCountProperty
,
value
);
}
}
public
static
readonly
DependencyProperty
ServerConnectionCountProperty
=
DependencyProperty
.
Register
(
nameof
(
ServerConnectionCount
),
typeof
(
int
),
typeof
(
MainWindow
),
new
PropertyMetadata
(
default
(
int
)));
public
int
ServerConnectionCount
{
get
{
return
(
int
)
GetValue
(
ServerConnectionCountProperty
);
}
set
{
SetValue
(
ServerConnectionCountProperty
,
value
);
}
}
private
readonly
Dictionary
<
SessionEventArgs
,
SessionListItem
>
sessionDictionary
=
new
Dictionary
<
SessionEventArgs
,
SessionListItem
>();
private
readonly
Dictionary
<
SessionEventArgs
,
SessionListItem
>
sessionDictionary
=
new
Dictionary
<
SessionEventArgs
,
SessionListItem
>();
private
SessionListItem
selectedSession
;
private
SessionListItem
selectedSession
;
...
@@ -59,6 +77,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -59,6 +77,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
proxyServer
.
BeforeResponse
+=
ProxyServer_BeforeResponse
;
proxyServer
.
BeforeResponse
+=
ProxyServer_BeforeResponse
;
proxyServer
.
TunnelConnectRequest
+=
ProxyServer_TunnelConnectRequest
;
proxyServer
.
TunnelConnectRequest
+=
ProxyServer_TunnelConnectRequest
;
proxyServer
.
TunnelConnectResponse
+=
ProxyServer_TunnelConnectResponse
;
proxyServer
.
TunnelConnectResponse
+=
ProxyServer_TunnelConnectResponse
;
proxyServer
.
ClientConnectionCountChanged
+=
delegate
{
Dispatcher
.
Invoke
(()
=>
{
ClientConnectionCount
=
proxyServer
.
ClientConnectionCount
;
});
};
proxyServer
.
ServerConnectionCountChanged
+=
delegate
{
Dispatcher
.
Invoke
(()
=>
{
ServerConnectionCount
=
proxyServer
.
ServerConnectionCount
;
});
};
proxyServer
.
Start
();
proxyServer
.
Start
();
proxyServer
.
SetAsSystemProxy
(
explicitEndPoint
,
ProxyProtocolType
.
AllHttp
);
proxyServer
.
SetAsSystemProxy
(
explicitEndPoint
,
ProxyProtocolType
.
AllHttp
);
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
84d4effc
...
@@ -124,7 +124,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -124,7 +124,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
throw
;
throw
;
}
}
Interlocked
.
Increment
(
ref
server
.
serverConnectionCount
);
server
.
UpdateServerConnectionCount
(
true
);
return
new
TcpConnection
return
new
TcpConnection
{
{
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
84d4effc
...
@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy
...
@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Backing field for corresponding public property
/// Backing field for corresponding public property
/// </summary>
/// </summary>
internal
int
serverConnectionCount
;
private
int
serverConnectionCount
;
/// <summary>
/// <summary>
/// A object that creates tcp connection to server
/// A object that creates tcp connection to server
...
@@ -199,6 +199,16 @@ namespace Titanium.Web.Proxy
...
@@ -199,6 +199,16 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
event
Func
<
object
,
TunnelConnectSessionEventArgs
,
Task
>
TunnelConnectResponse
;
public
event
Func
<
object
,
TunnelConnectSessionEventArgs
,
Task
>
TunnelConnectResponse
;
/// <summary>
/// Occurs when client connection count changed.
/// </summary>
public
event
EventHandler
ClientConnectionCountChanged
;
/// <summary>
/// Occurs when server connection count changed.
/// </summary>
public
event
EventHandler
ServerConnectionCountChanged
;
/// <summary>
/// <summary>
/// External proxy for Http
/// External proxy for Http
/// </summary>
/// </summary>
...
@@ -752,7 +762,7 @@ namespace Titanium.Web.Proxy
...
@@ -752,7 +762,7 @@ namespace Titanium.Web.Proxy
private
async
Task
HandleClient
(
TcpClient
tcpClient
,
ProxyEndPoint
endPoint
)
private
async
Task
HandleClient
(
TcpClient
tcpClient
,
ProxyEndPoint
endPoint
)
{
{
Interlocked
.
Increment
(
ref
clientConnectionCount
);
UpdateClientConnectionCount
(
true
);
tcpClient
.
ReceiveTimeout
=
ConnectionTimeOutSeconds
*
1000
;
tcpClient
.
ReceiveTimeout
=
ConnectionTimeOutSeconds
*
1000
;
tcpClient
.
SendTimeout
=
ConnectionTimeOutSeconds
*
1000
;
tcpClient
.
SendTimeout
=
ConnectionTimeOutSeconds
*
1000
;
...
@@ -770,7 +780,7 @@ namespace Titanium.Web.Proxy
...
@@ -770,7 +780,7 @@ namespace Titanium.Web.Proxy
}
}
finally
finally
{
{
Interlocked
.
Decrement
(
ref
clientConnectionCount
);
UpdateClientConnectionCount
(
false
);
try
try
{
{
...
@@ -799,5 +809,33 @@ namespace Titanium.Web.Proxy
...
@@ -799,5 +809,33 @@ namespace Titanium.Web.Proxy
endPoint
.
Listener
.
Stop
();
endPoint
.
Listener
.
Stop
();
endPoint
.
Listener
.
Server
.
Dispose
();
endPoint
.
Listener
.
Server
.
Dispose
();
}
}
internal
void
UpdateClientConnectionCount
(
bool
increment
)
{
if
(
increment
)
{
Interlocked
.
Increment
(
ref
clientConnectionCount
);
}
else
{
Interlocked
.
Decrement
(
ref
clientConnectionCount
);
}
ClientConnectionCountChanged
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
internal
void
UpdateServerConnectionCount
(
bool
increment
)
{
if
(
increment
)
{
Interlocked
.
Increment
(
ref
serverConnectionCount
);
}
else
{
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
}
ServerConnectionCountChanged
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
}
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
84d4effc
...
@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy
...
@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy
{
{
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
,
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
,
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
UpdateServerConnectionCount
(
false
);
}
}
return
;
return
;
...
@@ -344,7 +344,7 @@ namespace Titanium.Web.Proxy
...
@@ -344,7 +344,7 @@ namespace Titanium.Web.Proxy
else
if
(!
connection
.
HostName
.
Equals
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
))
else
if
(!
connection
.
HostName
.
Equals
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
))
{
{
connection
.
Dispose
();
connection
.
Dispose
();
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
UpdateServerConnectionCount
(
false
);
connection
=
await
GetServerConnection
(
args
);
connection
=
await
GetServerConnection
(
args
);
}
}
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
84d4effc
...
@@ -227,7 +227,7 @@ namespace Titanium.Web.Proxy
...
@@ -227,7 +227,7 @@ namespace Titanium.Web.Proxy
if
(
serverConnection
!=
null
)
if
(
serverConnection
!=
null
)
{
{
serverConnection
.
Dispose
();
serverConnection
.
Dispose
();
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
UpdateServerConnectionCount
(
false
);
}
}
}
}
}
}
...
...
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