Skip to content

Commit

Permalink
Refactor PacketArival to PacketReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Jul 12, 2021
1 parent b768abf commit a0f3bb0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions VpnHood.Client.Device.Android/AppVpnService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AppVpnService : VpnService, IPacketCapture
private int _mtu;
private IPAddress[] _dnsServers = new IPAddress[] { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4") };
public const string VpnServiceName = "VpnHood";
public event EventHandler<PacketCaptureArrivalEventArgs> OnPacketArrivalFromInbound;
public event EventHandler<PacketReceivedEventArgs> OnPacketReceivedFromInbound;
public event EventHandler OnStopped;
public bool Started => _mInterface != null;
public bool IsIncludeNetworksSupported => true;
Expand Down Expand Up @@ -166,7 +166,7 @@ protected virtual void ProcessPacket(IPPacket ipPacket)
{
try
{
OnPacketArrivalFromInbound?.Invoke(this, new PacketCaptureArrivalEventArgs(new[] { ipPacket }, this));
OnPacketReceivedFromInbound?.Invoke(this, new PacketReceivedEventArgs(new[] { ipPacket }, this));
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Client.Device.WinDivert/WinDivertPacketCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WinDivertPacketCapture : IPacketCapture
private WinDivertHeader _lastCaptureHeader;

protected readonly SharpPcap.WinDivert.WinDivertDevice _device;
public event EventHandler<PacketCaptureArrivalEventArgs> OnPacketArrivalFromInbound;
public event EventHandler<PacketReceivedEventArgs> OnPacketReceivedFromInbound;
public event EventHandler OnStopped;

public bool Started => _device.Started;
Expand Down Expand Up @@ -75,8 +75,8 @@ protected virtual void ProcessPacket(IPPacket ipPacket)
{
try
{
var eventArgs = new PacketCaptureArrivalEventArgs(new[] { ipPacket }, this); //todo: share buffer
OnPacketArrivalFromInbound?.Invoke(this, eventArgs);
var eventArgs = new PacketReceivedEventArgs(new[] { ipPacket }, this); //todo: share buffer
OnPacketReceivedFromInbound?.Invoke(this, eventArgs);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Client.Device/IPacketCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface IPacketCapture : IDisposable
bool CanProtectSocket { get; }
void ProtectSocket(System.Net.Sockets.Socket socket);
void SendPacketToInbound(IEnumerable<IPPacket> packets);
event EventHandler<PacketCaptureArrivalEventArgs> OnPacketArrivalFromInbound;
event EventHandler<PacketReceivedEventArgs> OnPacketReceivedFromInbound;

bool CanSendPacketToOutbound { get; }
void SendPacketToOutbound(IEnumerable<IPPacket> ipPackets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace VpnHood.Client.Device
{
public class PacketCaptureArrivalEventArgs : EventArgs
public class PacketReceivedEventArgs : EventArgs
{
public IEnumerable<IPPacket> IpPackets { get; }
public IPacketCapture PacketCapture { get; }
public PacketCaptureArrivalEventArgs(IEnumerable<IPPacket> ipPackets, IPacketCapture packetCapture)
public PacketReceivedEventArgs(IEnumerable<IPPacket> ipPackets, IPacketCapture packetCapture)
{
IpPackets = ipPackets ?? throw new ArgumentNullException(nameof(ipPackets));
PacketCapture = packetCapture ?? throw new ArgumentNullException(nameof(packetCapture));
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Client/VpnHoodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public async Task Connect()
_packetCapture.StartCapture();
}

_packetCapture.OnPacketArrivalFromInbound += PacketCapture_OnPacketArrivalFromInbound;
_packetCapture.OnPacketReceivedFromInbound += PacketCapture_OnPacketReceivedFromInbound;
State = ClientState.Connected;
}
catch (Exception ex)
Expand Down Expand Up @@ -284,7 +284,7 @@ private void Tunnel_OnPacketReceived(object sender, ChannelPacketReceivedEventAr
}

// WARNING: Performance Critical!
private void PacketCapture_OnPacketArrivalFromInbound(object sender, PacketCaptureArrivalEventArgs e)
private void PacketCapture_OnPacketReceivedFromInbound(object sender, Device.PacketReceivedEventArgs e)
{
if (_disposed)
return;
Expand Down Expand Up @@ -748,7 +748,7 @@ public void Dispose()

// close PacketCapture
_packetCapture.OnStopped -= PacketCature_OnStopped;
_packetCapture.OnPacketArrivalFromInbound -= PacketCapture_OnPacketArrivalFromInbound;
_packetCapture.OnPacketReceivedFromInbound -= PacketCapture_OnPacketReceivedFromInbound;
if (!_leavePacketCaptureOpen)
{
VhLogger.Instance.LogTrace($"Disposing the PacketCapture...");
Expand Down

0 comments on commit a0f3bb0

Please sign in to comment.