Example #1
0
        /// <summary>
        /// Serialize a work unit so it goes over the wire to a device.
        /// The structure must be common to all devices and algorithm implementations but the header can really be
        /// arbitrary payload as long as it's in the format the device expects.
        /// Each algorithm implementation takes a different payload so this can't just consume a <see cref="RequestedWork"/>.
        /// </summary>
        /// <returns>Opaque blob to send back to device.</returns>
        static internal byte[] YourWork(uint wid, IReadOnlyList <byte> payload)
        {
            var blob  = new byte[1 + 4 + payload.Count];
            var store = StoreOps.StoreKind(blob, OutgoingKind.WorkUnit);

            store = StoreOps.StoreUint(store, wid);
            store = StoreOps.StoreByteList(store, payload);
            ThrowIfNotFullyConsumed(store);
            return(blob);
        }
Example #2
0
        /// <summary>
        /// Construct the reply to <see cref="TurnOnArgs{A}"/>. In line of principle you could not-reply to
        /// some devices as they could be mangled by somebody else but... for the time being it's just a matter
        /// of giving back the server address to perform unicast packet transmissions.
        /// </summary>
        /// <param name="reachme">An unicast address the device who originally talked can contact me.</param>
        /// <param name="identificator">Currently unused.</param>
        /// <param name="deviceSpecific">Currently unused.</param>
        /// <returns>
        /// Blob to send over the wire. I won't touch it anymore. If I don't want to deal with this device
        /// (maybe it belongs to another server) I will return null and you send nothing to it.
        /// </returns>
        static internal byte[]? Welcome(IPAddress reachme, byte[] identificator, byte[] deviceSpecific)
        {
            var addrBlob = reachme.GetAddressBytes();
            var blob     = new byte[1 + 1 + addrBlob.Length];
            var store    = StoreOps.StoreKind(blob, OutgoingKind.ServerAddress);

            store = StoreOps.StoreByte(store, 0); // this is really a bitflag of features. For the time being it must be zero so no big deal
            store = StoreOps.StoreByteArray(store, addrBlob);
            ThrowIfNotFullyConsumed(store);
            return(blob);
        }