Search Unity

Questions about INetworkPipelineStage (Unity Transport)

Discussion in 'Unity Transport' started by Kichang-Kim, Sep 17, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    659
    Hi. I'm working on replacing LLAPI to Unity Transport, and stuck on implementing custom pipelines.

    Here is INetworkPipelineStage interface from source code:
    Code (CSharp):
    1. public interface INetworkPipelineStage
    2. {
    3.     NativeSlice<byte> Receive(NetworkPipelineContext ctx, NativeSlice<byte> inboundBuffer, ref bool needsResume, ref bool needsUpdate, ref bool needsSendUpdate);
    4.     InboundBufferVec Send(NetworkPipelineContext ctx, InboundBufferVec inboundBuffer, ref bool needsResume, ref bool needsUpdate);
    5.  
    6.     void InitializeConnection(NativeSlice<byte> sendProcessBuffer, NativeSlice<byte> recvProcessBuffer, NativeSlice<byte> sharedProcessBuffer);
    7.  
    8.     int ReceiveCapacity { get; }
    9.     int SendCapacity { get; }
    10.     int HeaderCapacity { get; }
    11.     int SharedStateCapacity { get; }
    12. }
    Surprisingly, there is no documentations and comments about this even though this is essential peace for getting same functionality to LLAPI.

    From this interface, what do each methods and parameters mean? what is needsUpdate, needsResume? What differences between each buffers?

    Thanks.
     
  2. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    659
    After investigating & try and errors, I learned basic things for implementing custom pipelines.

    1. Create custom pipeline struct inheriting INetworkPipelineStage.
    2. Create custom pipeline collection struct inheriting INetworkPipelineStageCollection. This also can be created via built-in generator. (In Multiplayer>CodeGen>PipelineCollection Generator menu.)
    3. Create custom NetworkDriver struct, wrapping
    GenericNetworkDriver<IPv4UDPSocket, YOUR STAGE COLLECTION TYPE>
    . This is important, because built-in UdpNetworkDriver used DefaultPipelineStageCollection, which has only built-in pipeline stages so you can't use your custom pipeline stage.
    4. Finally, you can create pipeline using your custom pipeline stages.

    Also, here is my understanding about each parameters:

    needsResume : if this set to true, processing method is called for incoming/outcoming request repeatedly. So if you need to split input packet to multiple output packet, you should set this to true.

    needsUpdate/needsSendUpdate : If this set to true, processing method is called in next update, even though there is no incoming requests (maybe). Unity used this flag for sending ack packet in reliable pipeline.

    SendBuffer : buffer for sending process, per connection. this buffer is permanent to single connection.
    ReceiveBuffer : buffer for receiving process, per connection. this buffer is permanent to single connection.
    SharedBuffer : buffer can be accessed both send method and receive method. Also this buffer is permanent to single connection.
     
unityunity