Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [0.8.0] - 2021-03-23
### New features
* Added overloads of `PopEvent` and `PopEventForConnection` which return the pipeline used as an out parameter.

### Changes

### Fixes
* Fixed some compatility issues with tiny.
* Fixed a crash when sending messages slightly less than one MTU using the fragmentation pipeline.
* Fixed a bug causing `NetworkDriver.RemoteEndPoint` to return an invalid value when using the default network interface.

### Upgrade guide

## [0.7.0] - 2021-02-05
### New features
* Added `DataStreamWriter.WriteRawbits` and `DataStreamWriter.ReadRawBits` for reading and writing raw bits from a data stream.

### Changes
* Optimized the `NetworkCompressionModel` to find buckets in constant time.
* Changed the error behavior of `DataStreamReader` to be consistent between the editor and players.

### Fixes
* Fixed a crash when receiving a packet with an invalid pipeline identifier

### Upgrade guide

## [0.6.0] - 2020-11-26
### New features
* An error handling pass has been made and `Error.StatusCode` have been added to indicate more specific errors.
* `Error.DisconnectReason` has been added, so when NetworkDriver.PopEvent returns a `NetworkEvent.Type.Disconnect` the reader returned contains 1 byte of data indicating the reason.

### Changes
* The function signature for NetworkDriver.BeginSend has changed. It now returns a `int` value indicating if the function succeeded or not and the DataStreamWriter now instead is returned as a `out` parameter.
* The function signature for INetworkInterface.Initialize has changed. It now requires you to return a `int` value indicating if the function succeeded or not.
* The function signature for INetworkInterface.CreateInterfaceEndPoint has changed. It now requires you to return a `int` value indicating if the function succeeded or not, and NetworkInterfaceEndPoint is now returned as a `out` parameter.

### Fixes
* Fixed a potential crash when receiving a malformated packet.
* Fixed an issue where the DataStream could sometimes fail writing packet uints before the buffer was full.

### Upgrade guide
* `NetworkDriver.BeginSend` now returns a `int` indicating a `Error.StatusCode`, and the `DataStreamWriter` is passed as an `out` parameter.
  • Loading branch information
Unity Technologies committed Mar 23, 2021
1 parent bda56ac commit 8750010
Show file tree
Hide file tree
Showing 26 changed files with 508 additions and 196 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Change log

## [0.8.0] - 2021-03-23
### New features
* Added overloads of `PopEvent` and `PopEventForConnection` which return the pipeline used as an out parameter.

### Changes

### Fixes
* Fixed some compatility issues with tiny.
* Fixed a crash when sending messages slightly less than one MTU using the fragmentation pipeline.
* Fixed a bug causing `NetworkDriver.RemoteEndPoint` to return an invalid value when using the default network interface.

### Upgrade guide

## [0.7.0] - 2021-02-05
### New features
* Added `DataStreamWriter.WriteRawbits` and `DataStreamWriter.ReadRawBits` for reading and writing raw bits from a data stream.

### Changes
* Optimized the `NetworkCompressionModel` to find buckets in constant time.
* Changed the error behavior of `DataStreamReader` to be consistent between the editor and players.

### Fixes
* Fixed a crash when receiving a packet with an invalid pipeline identifier

### Upgrade guide

## [0.6.0] - 2020-11-26
### New features
* An error handling pass has been made and `Error.StatusCode` have been added to indicate more specific errors.
Expand Down
20 changes: 20 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Unity Transport Design Rules

## All features are optional
Unity transport is conceptually a thin layer on UDP adding a connection concept. All additional features on top of UDP + connection are optional, when not used they have zero performance or complexity overhead. If possible features are implemented as pipeline stages.

Features that have a limited audience are implemented outside the package - either in game code or other packages.

## Full control over processing time and when packets are sent/received
UTP is optimized for making games. It can be used without creating any additional threads - only using the JobSystem. The layer on top has full control over when the transport schedules jobs. The layer on top also has full control over when packets are sent on the wire. There are no internal buffers delaying messages (except possibly in pipelines).

There is generally no need to continuously poll for messages since incoming data needs to be read right before simulation starts, and we cannot start using new data in the middle of the simulation

## Written in HPC#
All code is jobified and burst compiled, there is no garbage collection. The transport does not spend any processing time outside setup on the main thread, and it allows the layer on top to not sync on the main thread.

## Follows the DOTS principles, is usable in DOTS Runtime and always compatible with the latest versions of the DOTS packages
There should always be a version compatible with the latest verions of the DOTS dependencies such as Unity Collections.

## The protocol is well defined and documented
Other implementations can communicate with games written with Unity Transport, without reverse engineering or reading the transport source code
7 changes: 7 additions & 0 deletions DESIGN.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions Runtime/BaselibNetworkInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,15 @@ public unsafe NetworkEndPoint GetGenericEndPoint(NetworkInterfaceEndPoint endpoi
{
// Set to a valid address so length is set correctly
var address = NetworkEndPoint.LoopbackIpv4;
UnsafeUtility.MemCpy(&address.rawNetworkAddress, endpoint.data, endpoint.dataLength);
var error = default(ErrorState);
var slice = m_LocalAndTempEndpoint.AtIndexAsSlice(0, (uint)Binding.Baselib_RegisteredNetwork_Endpoint_MaxSize);
NetworkEndpoint local;
local.slice = slice;
local.slice.size = (uint)endpoint.dataLength;
UnsafeUtility.MemCpy((void*)local.slice.data, endpoint.data, endpoint.dataLength);
Binding.Baselib_RegisteredNetwork_Endpoint_GetNetworkAddress(local, &address.rawNetworkAddress, &error);
if (error.code != ErrorCode.Success)
return default;
return address;
}

Expand Down Expand Up @@ -333,7 +341,9 @@ public unsafe void Execute()
var remote = packet.remoteEndpoint.slice;
address.dataLength = (int)remote.size;
UnsafeUtility.MemCpy(address.data, (void*)remote.data, (int)remote.size);
Receiver.ReceiveCount += Receiver.AppendPacket(address, *(UdpCHeader*)packet.payload.data, receivedBytes);
//FIXME: remove when burst 1.5 fix the problem
var temp = (UdpCHeader*)packet.payload.data;
Receiver.ReceiveCount += Receiver.AppendPacket(address, *temp,receivedBytes);
}
// Reuse the requests after they have been processed.
for (int i = 0; i < count; i++)
Expand Down Expand Up @@ -475,7 +485,7 @@ public unsafe NetworkSendInterface CreateSendInterface()
};
}

[BurstCompile]
[BurstCompile(DisableDirectCall = true)]
[AOT.MonoPInvokeCallback(typeof(NetworkSendInterface.BeginSendMessageDelegate))]
private static unsafe int BeginSendMessage(out NetworkInterfaceSendHandle handle, IntPtr userData, int requiredPayloadSize)
{
Expand All @@ -499,7 +509,7 @@ private static unsafe int BeginSendMessage(out NetworkInterfaceSendHandle handle
return (int)Error.StatusCode.Success;
}

[BurstCompile]
[BurstCompile(DisableDirectCall = true)]
[AOT.MonoPInvokeCallback(typeof(NetworkSendInterface.EndSendMessageDelegate))]
private static unsafe int EndSendMessage(ref NetworkInterfaceSendHandle handle, ref NetworkInterfaceEndPoint address, IntPtr userData, ref NetworkSendQueueHandle sendQueueHandle)
{
Expand All @@ -523,12 +533,12 @@ private static unsafe int EndSendMessage(ref NetworkInterfaceSendHandle handle,
if (error.code != ErrorCode.Success)
{
baselib->m_PayloadsTx.ReleaseHandle(index);
return -(int)error.code;
return (int) error.code == -1 ? -1 : -(int) error.code;
}
return handle.size;
}

[BurstCompile]
[BurstCompile(DisableDirectCall = true)]
[AOT.MonoPInvokeCallback(typeof(NetworkSendInterface.AbortSendMessageDelegate))]
private static unsafe void AbortSendMessage(ref NetworkInterfaceSendHandle handle, IntPtr userData)
{
Expand Down
Loading

0 comments on commit 8750010

Please sign in to comment.