/// <summary> /// Convert raw message to BabelMessage. /// Called by a port with an incoming raw message. /// Must return as soon as possible, so convert and put on incoming Q for later relay. /// Caller frees the underlying raw message. /// TODO: Process long message if necessary: start a long list. /// </summary> /// <param name="exchange"></param> /// <param name="mtx"></param> /// <returns></returns> public static byte ProcessIncomingRawMesssage(MessageExchange exchange, MessageTransaction mtx) { PacketBuffer g = mtx.MsgBuffer; BabelMessage m = new BabelMessage(exchange); m.Pid = (byte)(g.flagsPid & ProtocolConstants.PID_MASK); m.Verified = (m.Pid == ProtocolConstants.PID_GENERAL_V); m.Receiver = ProtocolConstants.ADRS_LOCAL; m.FlagsRS = g.flagsRS(); m.IncomingNetIfIndex = mtx.ONetIfIndex; m.OutgoingNetIfIndex = ProtocolConstants.NETIF_UNSET; m.Cmd = 0; switch (m.Pid) { case ProtocolConstants.PID_GENERAL: case ProtocolConstants.PID_GENERAL_V: m.IsGeneral = true; m.IsHandshake = false; m.Receiver = g.receiver(); m.Cmd = g.command(); m.FlagsRS = g.flagsRS(); break; default: return(1); } m.Sender = g.sender(); m.SenderId = g.senderId(); m.DataLen = g.dataLength(); m.DataAry = mtx.CopyMessageData(); // Now submit message to be relayed later. exchange.SubmitIncomingMessage(m); return(0); }
public MessageReceiverThread(MessageExchange exchange) { Exchange = exchange; Task = new Thread(new ThreadStart(Run)); Task.Name = "MessageReceiverThread"; Task.Priority = ThreadPriority.AboveNormal; }
public MediatorNetIf(NetIfManager manager, MessageExchange exchange) : base(manager, new VirtualDevice("Mediator"), ProtocolConstants.NETIF_MEDIATOR_PORT, false, true, false, true) { Exchange = exchange; SchedulerInterval = 1; IsoTaskQueue = new int[IsoTaskSize]; IsoTasks = new IsoTask[IsoTaskSize]; for (int k = 0; k < IsoTaskSize; ++k) { IsoTasks[k] = new IsoTask(); } InitTasks(); }
public MessageBinder(MessageExchange exchange, BabelMessage message, MessageExchange.IMessageHandler handler, MessageExchange.MessageHandlerKind kind, Object context, byte ident, int numReplies) { Exchange = exchange; Message = message; Reply = null; Handler = handler; Kind = kind; Context = context; Ident = ident; NumReplies = numReplies; ElapsedTime = DateTime.UtcNow.Ticks; }
public static BabelMessage CreateHandshakeMessage(MessageExchange exchange, Router.RouterAction dispatch, byte postNetIfIndex, byte pid, byte arg) { BabelMessage m = new BabelMessage(exchange); m.IsHandshake = true; m.IsGeneral = false; m.Pid = pid; m.Arg = arg; m.PostNetIfIndex = postNetIfIndex; m.Dispatch = dispatch; m.IncomingNetIfIndex = ProtocolConstants.NETIF_UNSET; m.OutgoingNetIfIndex = ProtocolConstants.NETIF_UNSET; return(m); }
public static BabelMessage CreateCommandMessage(MessageExchange exchange, bool verified, Router.RouterAction dispatch, byte postNetIfIndex, byte cmd, ushort receiver, ushort sender, byte flagsRS, byte ident, byte dataLen, byte dataOffset, byte[] dataAry) { BabelMessage m; if (dataLen >= ProtocolConstants.GENERAL_TAIL_SIZE) { return(null); // Longer messages not implemented yet. } m = new BabelMessage(exchange); m.IsHandshake = false; m.IsGeneral = true; m.Verified = verified; m.PostNetIfIndex = postNetIfIndex; m.Dispatch = dispatch; m.IncomingNetIfIndex = ProtocolConstants.NETIF_UNSET; m.OutgoingNetIfIndex = ProtocolConstants.NETIF_UNSET; m.Cmd = cmd; m.Receiver = receiver; m.Sender = sender; m.FlagsRS = flagsRS; m.SenderId = ident; m.DataLen = dataLen; if (dataOffset <= 0) { m.DataAry = dataAry; } else { byte[] ary = new byte[dataAry.Length + dataOffset]; Array.Copy(dataAry, 0, ary, dataOffset, dataAry.Length); m.DataAry = ary; } return(m); }
// Log a message to Log port (default isNETIF_USB_DEV_0). // Prefixes BabelMilliTicker binary value to start. // Truncates message if too long. // Returns zero on success. public static int Logger(MessageExchange exchange, byte logNetIfIndex, byte[] buffer) { byte len = Primitives.Strlen(buffer); byte max = (byte)(exchange.Manager.MaxPacketSize - ProtocolConstants.GENERAL_OVERHEADS_SIZE - ProtocolConstants.TICKER_SIZE); if (len > max) { len = max; } BabelMessage message = BabelMessage.CreateCommandMessage(exchange, false, Router.RouterAction.PostToNetIf, logNetIfIndex, ProtocolConstants.MEDIATOR_DEVICE_LOG, ProtocolConstants.ADRS_LOCAL, ProtocolConstants.ADRS_LOCAL, 0, ProtocolConstants.IDENT_MEDIATOR, len, ProtocolConstants.TICKER_SIZE, buffer); byte[] tmp = Primitives.UIntToByteArray(Primitives.GetBabelMilliTicker()); Array.Copy(tmp, message.DataAry, tmp.Length); if (!message.Exchange.SubmitMessage(message, null, false, 0)) { return(1); } return(0); }
private BabelMessage(MessageExchange exchange) { Exchange = exchange; LastError = MessageError.None; CurrentBlock = 0; }
public ProtocolHub(MessageExchange exchange) { Exchange = exchange; IncomingQueues = new ConcurrentDictionary <int, LinkedBlockingCollection <BabelMessage> >(); }