public GcPeer(int peerId, PeerConnection connection) { _writer = new NetWriter(); _connection = connection; _relayedPeerIds = new Dictionary <GcConnection, int>(); PeerId = peerId; }
public GcPeer(int peerId, GcPeer concretePeer) { _writer = new NetWriter(); _relayedPeerIds = new Dictionary <GcConnection, int>(); PeerId = peerId; IsVirtual = true; _concretePeer = concretePeer; }
/// <summary> /// Packs the message into <see cref="NetWriter"/> /// </summary> /// <param name="writer"></param> /// <param name="writeAction"></param> /// <param name="opCode"></param> /// <param name="requestId"></param> /// <param name="responseId"></param> /// <param name="status"></param> /// <param name="defaultFlags"></param> public static void PackMessage(NetWriter writer, short opCode, Action <NetWriter> writeAction, int?requestId, int?responseId, ResponseStatus?status, int?peerId, byte defaultFlags = 0) { // Move to front of the buffer writer.SetPosition(0); var flags = defaultFlags; if (requestId.HasValue) { flags |= MessageFlags.Request; } if (responseId.HasValue) { flags |= MessageFlags.Response; } if (peerId.HasValue) { flags |= MessageFlags.PaddedPeerId; } // Write flags writer.Write(flags); // Write opCode writer.Write(opCode); // Add peer id if it's provided if (peerId.HasValue) { writer.Write(peerId.Value); } // Write *optional* data if (requestId.HasValue) { writer.Write(requestId.Value); } if (responseId.HasValue) { writer.Write(responseId.Value); writer.Write((byte)(status ?? ResponseStatus.Default)); } // Write message content writeAction(writer); }
public GcConnection(IConnectionImplementation implementation) { // Generate instance id for better hashing _instanceId = Interlocked.Increment(ref _instanceIdGenerator); _relayedPeers = new ConcurrentDictionary <int, GcPeer>(); _responseCallbacks = new ConcurrentDictionary <int, TaskCompletionSource <GcMessage> >(); _timeoutMessage = new GcMessage(null, 0) { Status = ResponseStatus.Timeout }; Implementation = implementation; implementation.DataReceived += OnDataReceived; implementation.Disconnected += OnDisconnected; _writer = new NetWriter(); }