VpnHood.Net.PacketTransports 9.1.874

dotnet add package VpnHood.Net.PacketTransports --version 9.1.874
                    
NuGet\Install-Package VpnHood.Net.PacketTransports -Version 9.1.874
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VpnHood.Net.PacketTransports" Version="9.1.874" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VpnHood.Net.PacketTransports" Version="9.1.874" />
                    
Directory.Packages.props
<PackageReference Include="VpnHood.Net.PacketTransports" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add VpnHood.Net.PacketTransports --version 9.1.874
                    
#r "nuget: VpnHood.Net.PacketTransports, 9.1.874"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package VpnHood.Net.PacketTransports@9.1.874
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=VpnHood.Net.PacketTransports&version=9.1.874
                    
Install as a Cake Addin
#tool nuget:?package=VpnHood.Net.PacketTransports&version=9.1.874
                    
Install as a Cake Tool

VpnHood.Net.PacketTransports

Packet queues for .NET: a transport takes IP packets from many senders, queues them, and hands them to your code on a sending loop of its own, while the packets your code reads go up through one event. It is how VpnHood moves packets between its tunnels, its adapters and its TCP stack, and works for any channel of VpnHood.Net.Packets packets: a device, a socket, a pipe.

dotnet add package VpnHood.Net.PacketTransports

How it works

  • IPacketTransport is the two-way contract: SendPacketQueued and SendPacketQueuedAsync queue a packet to send, and PacketReceived raises each packet received.
  • Derive from the base that fits how your channel writes:
    • PacketTransport hands over batches, up to the queue's capacity at a time;
    • SinglePacketTransport hands over one packet at a time;
    • PassthroughPacketTransport has no queue: each packet goes on at once, on the sender's thread.
  • PacketTransportOptions sets the queue: its capacity, whether a send to a full queue waits for room (Blocking, up to BlockingTimeout) or drops the oldest packet, and whether the transport disposes each packet once sent (AutoDisposePackets).
  • A packet has one owner at a time. One sent to the transport is the transport's, whatever the outcome; one raised by PacketReceived is the handler's, which forwards or disposes it, so attach one handler only.
  • PacketStat counts what is sent, received and dropped.
  • FairPacketQueue is a send queue split into lanes by a hash of a packet's ports, so one flow that floods fills mostly its own lane.

Quick start

The examples below run as a test in CI (PacketTransportsReadmeExampleTest.cs). Their namespaces are System.Net, VpnHood.Net.Packets, VpnHood.Net.Packets.Extensions and VpnHood.Net.PacketTransports.

A transport over your device

// A transport over your own device: the queue, its sending loop and the packet ownership come from the base.
public sealed class DeviceTransport() : PacketTransport(new PacketTransportOptions {
    AutoDisposePackets = true, // the base disposes each packet once SendPacketsAsync returns
    Blocking = false // a full queue drops its oldest packet instead of waiting for room
})
{
    public List<string> Written { get; } = [];

    // the sending loop hands over a batch at a time
    protected override ValueTask SendPacketsAsync(IReadOnlyList<IpPacket> ipPackets)
    {
        foreach (var ipPacket in ipPackets)
            Written.Add(ipPacket.ToString()); // write it to the device here
        return default;
    }

    // what the device reads goes up through PacketReceived
    public void OnDeviceRead(IpPacket ipPacket) => OnPacketReceived(ipPacket);
}

Send and receive

using var transport = new DeviceTransport();

// one handler, which owns each received packet: it forwards or disposes it
transport.PacketReceived += (_, ipPacket) => {
    Console.WriteLine($"Received: {ipPacket}");
    ipPacket.Dispose();
};

// a packet sent is the transport's from here, whatever the outcome
var packet = PacketBuilder.BuildUdp(
    new IPEndPoint(IPAddress.Parse("10.0.0.2"), 5353),
    new IPEndPoint(IPAddress.Parse("10.0.0.1"), 53),
    "query"u8);
packet.UpdateAllChecksums();
transport.SendPacketQueued(packet);

Packages

  • VpnHood.Net.PacketTransports — the transports
  • VpnHood.Net.Packets — the packets they carry

Requires .NET 11.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on VpnHood.Net.PacketTransports:

Package Downloads
VpnHood.Core.Tunneling

The tunnel between a VpnHood client and server, which both share: its requests, channels and streams, and the forwarding of a session's packets.

VpnHood.Net.VpnAdapters.Abstractions

The VPN adapter contract: a virtual network interface whose packets a VPN reads and writes, the base class every platform's TUN adapter extends, and a null adapter.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.1.874 0 11/15/2026
9.1.864 226 11/3/2026
9.0.860 233 10/31/2026
9.0.859.16-prerelease 200 10/30/2026
9.0.857 234 10/20/2026
9.0.856 225 10/19/2026
9.0.855 227 10/13/2026
8.2.853.11-prerelease 220 10/5/2026
8.2.853 239 9/23/2026
8.2.852 227 9/23/2026