Exemplo n.º 1
0
 /// <summary>
 /// Instantiates.
 /// </summary>
 /// <param name="config"></param>
 public CoapStack(ICoapConfig config)
 {
     this.AddLast("Observe", new ObserveLayer(config));
     this.AddLast("Blockwise", new BlockwiseLayer(config));
     this.AddLast("Token", new TokenLayer(config));
     this.AddLast("Reliability", new ReliabilityLayer(config));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Instantiates a new endpoint with the
 /// specified channel and configuration.
 /// </summary>
 public CoAPEndPoint(IChannel channel, ICoapConfig config)
 {
     _config = config;
     _channel = channel;
     _matcher = new Matcher(config);
     _coapStack = new CoapStack(config);
     _channel.DataReceived += ReceiveData;
 }
Exemplo n.º 3
0
        public CoapObserveRelation(Request request, IEndPoint endpoint, ICoapConfig config)
        {
            _config = config;
            _request = request;
            _endpoint = endpoint;
            _orderer = new ObserveNotificationOrderer(config);

            request.Reregistering += OnReregister;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs a new blockwise layer.
        /// </summary>
        public BlockwiseLayer(ICoapConfig config)
        {
            _maxMessageSize = config.MaxMessageSize;
            _defaultBlockSize = config.DefaultBlockSize;
            if (log.IsDebugEnabled)
                log.Debug("BlockwiseLayer uses MaxMessageSize: " + _maxMessageSize + " and DefaultBlockSize:" + _defaultBlockSize);

            config.PropertyChanged += ConfigChanged;
        }
Exemplo n.º 5
0
        // private int _period;

        public SweepDeduplicator(ICoapConfig config)
        {
            _config = config;
#if NETSTANDARD1_3
            _period = (int)config.MarkAndSweepInterval;
#else
            _timer          = new Timer(config.MarkAndSweepInterval);
            _timer.Elapsed += Sweep;
#endif
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a new blockwise layer.
        /// </summary>
        public BlockwiseLayer(ICoapConfig config)
        {
            _maxMessageSize   = config.MaxMessageSize;
            _defaultBlockSize = config.DefaultBlockSize;
            _blockTimeout     = config.BlockwiseStatusLifetime;
            log.Debug(m => m("BlockwiseLayer uses MaxMessageSize: {0} and DefaultBlockSize: {1}", _maxMessageSize,
                             _defaultBlockSize));

            config.PropertyChanged += ConfigChanged;
        }
Exemplo n.º 7
0
        public CoapObserveRelation(Request request, IEndPoint endpoint, ICoapConfig config)
        {
            _config   = config;
            Request   = request;
            _endpoint = endpoint;
            Orderer   = new ObserveNotificationOrderer(config);
            Request.ObserveRelation = this;

            request.Reregistering += OnReregister;
        }
Exemplo n.º 8
0
        public CoapStack(ICoapConfig config)
            : this(config.Port, config.TransferBlockSize, config.SequenceTimeout)
        {
#if COAPALL
            if (config.Spec != null)
            {
                _udpLayer.Spec = config.Spec;
            }
#endif
        }
Exemplo n.º 9
0
        private IDictionary <Exchange.KeyID, Exchange> _incommingMessages;   // for deduplication

        public EndpointSurveillant(String name, IEndPoint endpoint)
        {
            ICoapConfig config = endpoint.Config;

            _exchangeLifecycle       = config.ExchangeLifetime;
            _sweepDuplicatorInterval = (Int32)config.MarkAndSweepInterval;
            _name = name;

            ExtractMaps(endpoint);
        }
Exemplo n.º 10
0
 public CropRotation(ICoapConfig config)
 {
     _maps       = new ConcurrentDictionary <Exchange.KeyID, Exchange> [3];
     _maps[0]    = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
     _maps[1]    = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
     _maps[2]    = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
     _first      = 0;
     _second     = 1;
     _coapConfig = config;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Constructs a new blockwise layer.
        /// </summary>
        public BlockwiseLayer(ICoapConfig config)
        {
            _maxMessageSize   = config.MaxMessageSize;
            _defaultBlockSize = config.DefaultBlockSize;
            if (log.IsDebugEnabled)
            {
                log.Debug("BlockwiseLayer uses MaxMessageSize: " + _maxMessageSize + " and DefaultBlockSize:" + _defaultBlockSize);
            }

            config.PropertyChanged += ConfigChanged;
        }
Exemplo n.º 12
0
 public CropRotation(ICoapConfig config)
 {
     _maps = new ConcurrentDictionary<Exchange.KeyID, Exchange>[3];
     _maps[0] = new ConcurrentDictionary<Exchange.KeyID, Exchange>();
     _maps[1] = new ConcurrentDictionary<Exchange.KeyID, Exchange>();
     _maps[2] = new ConcurrentDictionary<Exchange.KeyID, Exchange>();
     _first = 0;
     _second = 1;
     _timer = new Timer(config.CropRotationPeriod);
     _timer.Elapsed += Rotation;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Instantiates.
        /// </summary>
        /// <param name="config"></param>
        public CoapStack(ICoapConfig config)
        {
            this.AddLast("Observe", new ObserveLayer(config));
#if INCLUDE_OSCOAP
            this.AddLast("SecureBlockwise", new OSCOAP.SecureBlockwiseLayer(config));
            this.AddLast("OSCOAP", new OSCOAP.OscoapLayer(config));
#endif
            this.AddLast("Blockwise", new BlockwiseLayer(config));
            this.AddLast("Token", new TokenLayer(config));
            this.AddLast("Reliability", new ReliabilityLayer(config));
        }
Exemplo n.º 14
0
 public TransmissionContext(ICoapConfig config, Exchange exchange, Message message, Action <TransmissionContext> retransmit)
 {
     _config          = config;
     _exchange        = exchange;
     _message         = message;
     _retransmit      = retransmit;
     _currentTimeout  = message.AckTimeout;
     _timer           = new Timer();
     _timer.AutoReset = false;
     _timer.Elapsed  += timer_Elapsed;
 }
Exemplo n.º 15
0
 public CropRotation(ICoapConfig config)
 {
     _maps           = new ConcurrentDictionary <Exchange.KeyID, Exchange> [3];
     _maps[0]        = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
     _maps[1]        = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
     _maps[2]        = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
     _first          = 0;
     _second         = 1;
     _timer          = new Timer(config.CropRotationPeriod);
     _timer.Elapsed += Rotation;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Constructs a new reliability layer.
        /// </summary>
        public ReliabilityLayer(ICoapConfig config)
        {
            _config = config;

            _ackTimeout         = _config.AckTimeout;
            _ackRandomFactor    = _config.AckRandomFactor;
            _ackTimeoutScale    = _config.AckTimeoutScale;
            _maxRetransmitCount = config.MaxRetransmit;

            _config.PropertyChanged += PropertyChanged;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Instantiates.
        /// </summary>
        /// <param name="uri">the Uri of remote resource</param>
        /// <param name="config">the config</param>
        public CoapClient(Uri uri, ICoapConfig config)
        {
            if (uri != null)
            {
                UriPath  = uri.AbsolutePath;
                UriQuery = uri.Query;
                Uri      = new Uri(uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
            }

            _config = config ?? CoapConfig.Default;
        }
Exemplo n.º 18
0
 public static ICommunicator CreateCommunicator(ICoapConfig config)
 {
     if (config.HttpPort > 0)
     {
         return(new ProxyCommunicator(config));
     }
     else
     {
         return(new CommonCommunicator(config));
     }
 }
Exemplo n.º 19
0
        public Matcher(ICoapConfig config)
        {
            _deduplicator = DeduplicatorFactory.CreateDeduplicator(config);
            if (config.UseRandomIDStart)
            {
                _currentID = new Random().Next(1 << 16);
            }
            _tokenLength = config.TokenLength;

            config.PropertyChanged += PropertyChanged;
        }
Exemplo n.º 20
0
        public SecureBlockwiseLayer(ICoapConfig config)
        {
            _maxMessageSize   = config.OSCOAP_MaxMessageSize;
            _defaultBlockSize = config.OSCOAP_DefaultBlockSize;
            _blockTimeout     = config.OSCOAP_BlockwiseStatusLifetime;
            if (log.IsDebugEnabled)
            {
                log.Debug("SecureBlockwiseLayer uses MaxMessageSize: " + _maxMessageSize + " and DefaultBlockSize:" + _defaultBlockSize);
            }

            config.PropertyChanged += ConfigChanged;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Constructs a new OSCAP layer.
        /// </summary>
        public OscoapLayer(ICoapConfig config)
        {
            _replayWindow = config.OSCOAP_ReplayWindow;
            if (_Log.IsInfoEnabled)
            {
                _Log.Info("OscoapLayer - replay=" + _replayWindow.ToString()); // Print out config if any
            }

            config.PropertyChanged += ConfigChanged;

            // _replayWindow = false;
        }
Exemplo n.º 22
0
        void ConfigChanged(Object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            ICoapConfig config = (ICoapConfig)sender;

            if (String.Equals(e.PropertyName, "MaxMessageSize"))
            {
                _maxMessageSize = config.MaxMessageSize;
            }
            else if (String.Equals(e.PropertyName, "DefaultBlockSize"))
            {
                _defaultBlockSize = config.DefaultBlockSize;
            }
        }
Exemplo n.º 23
0
        public CropRotation(ICoapConfig config)
        {
            _maps    = new ConcurrentDictionary <Exchange.KeyID, Exchange> [3];
            _maps[0] = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
            _maps[1] = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
            _maps[2] = new ConcurrentDictionary <Exchange.KeyID, Exchange>();
            _first   = 0;
            _second  = 1;
#if NETSTANDARD1_3
            _period = config.CropRotationPeriod;
#else
            _timer          = new Timer(config.CropRotationPeriod);
            _timer.Elapsed += Rotation;
#endif
        }
Exemplo n.º 24
0
        /// <summary>
        /// Constructs a server with the specified configuration that
        /// listens to the given ports.
        /// </summary>
        /// <param name="config">the configuration, or <code>null</code> for default</param>
        /// <param name="ports">the ports to bind to</param>
        public CoapServer(ICoapConfig config, params Int32[] ports)
        {
            _config    = config ?? CoapConfig.Default;
            _root      = new RootResource(this);
            _deliverer = new ServerMessageDeliverer(_config, _root);

            Resource wellKnown = new Resource(".well-known", false);

            wellKnown.Add(new DiscoveryResource(_root));
            _root.Add(wellKnown);

            foreach (Int32 port in ports)
            {
                Bind(port);
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Constructs a new observe relation.
 /// </summary>
 /// <param name="config">the config</param>
 /// <param name="endpoint">the observing endpoint</param>
 /// <param name="resource">the observed resource</param>
 /// <param name="exchange">the exchange that tries to establish the observe relation</param>
 public ObserveRelation(ICoapConfig config, ObservingEndpoint endpoint, IResource resource, Exchange exchange)
 {
     if (config == null)
         throw ThrowHelper.ArgumentNull("config");
     if (endpoint == null)
         throw ThrowHelper.ArgumentNull("endpoint");
     if (resource == null)
         throw ThrowHelper.ArgumentNull("resource");
     if (exchange == null)
         throw ThrowHelper.ArgumentNull("exchange");
     _config = config;
     _endpoint = endpoint;
     _resource = resource;
     _exchange = exchange;
     _key = String.Format("{0}#{1}", Source, exchange.Request.TokenString);
 }
Exemplo n.º 26
0
        public CoapServer(ICoapConfig config, IResource rootResource, System.Net.EndPoint endPoint, params int[] ports)
        {
            Config     = config ?? CoapConfig.Default;
            _root      = rootResource ?? new RootResource(this);
            _deliverer = new ServerMessageDeliverer(Config, _root);

            Resource wellKnown = new Resource(".well-known", false);

            wellKnown.Add(new DiscoveryResource(_root));
            _root.Add(wellKnown);

            _endPointSupplied = endPoint;
            foreach (int port in ports)
            {
                Bind(port);
            }
        }
Exemplo n.º 27
0
        public MockStack(Type[] layers, ICoapConfig config = null)
        {
            if (config == null)
            {
                config = CoapConfig.Default;
            }

            int i = 0;

            foreach (Type l in layers)
            {
                ILayer ll = (ILayer)Activator.CreateInstance(l, new object[] { config }, null);

                this.AddLast(i.ToString(), ll);
                i++;
            }
        }
Exemplo n.º 28
0
 public static IDeduplicator CreateDeduplicator(ICoapConfig config)
 {
     String type = config.Deduplicator;
     if (String.Equals(MarkAndSweepDeduplicator, type, StringComparison.OrdinalIgnoreCase)
         || String.Equals("DEDUPLICATOR_MARK_AND_SWEEP", type, StringComparison.OrdinalIgnoreCase))
         return new SweepDeduplicator(config);
     else if (String.Equals(CropRotationDeduplicator, type, StringComparison.OrdinalIgnoreCase)
         || String.Equals("DEDUPLICATOR_CROP_ROTATIO", type, StringComparison.OrdinalIgnoreCase))
         return new CropRotation(config);
     else if (!String.Equals(NoopDeduplicator, type, StringComparison.OrdinalIgnoreCase)
         && !String.Equals("NO_DEDUPLICATOR", type, StringComparison.OrdinalIgnoreCase))
     {
         if (log.IsWarnEnabled)
             log.Warn("Unknown deduplicator type: " + type);
     }
     return new NoopDeduplicator();
 }
Exemplo n.º 29
0
        void ConfigChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            ICoapConfig config = (ICoapConfig)sender;

            if (string.Equals(e.PropertyName, "MaxMessageSize"))
            {
                _maxMessageSize = config.MaxMessageSize;
            }
            else if (string.Equals(e.PropertyName, "DefaultBlockSize"))
            {
                _defaultBlockSize = config.DefaultBlockSize;
            }
            else if (string.Equals(e.PropertyName, "BlockwiseStatusLifetime"))
            {
                _blockTimeout = config.BlockwiseStatusLifetime;
            }
        }
Exemplo n.º 30
0
            public TransmissionContext(ICoapConfig config, Exchange exchange, Message message, Action <TransmissionContext> retransmit, int maxRetransmitCount)
            {
                _config             = config;
                _exchange           = exchange;
                _message            = message;
                _retransmit         = retransmit;
                _maxRetransmitCount = maxRetransmitCount;
                CurrentTimeout      = message.AckTimeout;
#if NETSTANDARD1_3
#else
                _timer = new Timer()
                {
                    AutoReset = false
                };

                _timer.Elapsed += timer_Elapsed;
#endif
            }
Exemplo n.º 31
0
        private void PropertyChanged(object obj, PropertyChangedEventArgs args)
        {
            ICoapConfig config = (ICoapConfig)obj;

            switch (args.PropertyName)
            {
            default:
                break;

            case "AckTimeout":
                _ackTimeout = config.AckTimeout;
                break;

            case "AckRandomFactor":
                _ackRandomFactor = _config.AckRandomFactor;
                break;

            case "AckTimeoutScale":
                _ackTimeoutScale = _config.AckTimeoutScale;
                break;
            }
        }
Exemplo n.º 32
0
 /// <summary>
 /// Constructs a new observe relation.
 /// </summary>
 /// <param name="config">the config</param>
 /// <param name="endpoint">the observing endpoint</param>
 /// <param name="resource">the observed resource</param>
 /// <param name="exchange">the exchange that tries to establish the observe relation</param>
 public ObserveRelation(ICoapConfig config, ObservingEndpoint endpoint, IResource resource, Exchange exchange)
 {
     if (config == null)
     {
         throw ThrowHelper.ArgumentNull("config");
     }
     if (endpoint == null)
     {
         throw ThrowHelper.ArgumentNull("endpoint");
     }
     if (resource == null)
     {
         throw ThrowHelper.ArgumentNull("resource");
     }
     if (exchange == null)
     {
         throw ThrowHelper.ArgumentNull("exchange");
     }
     _config   = config;
     _endpoint = endpoint;
     _resource = resource;
     _exchange = exchange;
     _key      = String.Format("{0}#{1}", Source, exchange.Request.TokenString);
 }
Exemplo n.º 33
0
        public static IDeduplicator CreateDeduplicator(ICoapConfig config)
        {
            String type = config.Deduplicator;

            if (String.Equals(MarkAndSweepDeduplicator, type, StringComparison.OrdinalIgnoreCase) ||
                String.Equals("DEDUPLICATOR_MARK_AND_SWEEP", type, StringComparison.OrdinalIgnoreCase))
            {
                return(new SweepDeduplicator(config));
            }
            else if (String.Equals(CropRotationDeduplicator, type, StringComparison.OrdinalIgnoreCase) ||
                     String.Equals("DEDUPLICATOR_CROP_ROTATIO", type, StringComparison.OrdinalIgnoreCase))
            {
                return(new CropRotation(config));
            }
            else if (!String.Equals(NoopDeduplicator, type, StringComparison.OrdinalIgnoreCase) &&
                     !String.Equals("NO_DEDUPLICATOR", type, StringComparison.OrdinalIgnoreCase))
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn("Unknown deduplicator type: " + type);
                }
            }
            return(new NoopDeduplicator());
        }
        public MockMessagePump(Type[] layers, ICoapConfig configClient = null, ICoapConfig configServer = null)
        {
            if (configClient == null)
            {
                configClient = CoapConfig.Default;
            }

            if (configServer == null)
            {
                configServer = CoapConfig.Default;
            }

            ClientEndpoint = AddClientEndpoint("Client", (IPEndPoint)ClientAddress, configClient, layers, true);
            ClientStack    = ServerStacks[ClientAddress].First();

            AddServerEndpoint("Server #1", (IPEndPoint)ServerAddress, configServer, layers, true);
            MockStack x = ServerStacks[ServerAddress].First();

            AddEndpointToAddress((IPEndPoint)MulticastAddress, x);

            AddServerEndpoint("Server #2", (IPEndPoint)ServerAddress2, configServer, layers, true);
            x = ServerStacks[ServerAddress2].First();
            AddEndpointToAddress((IPEndPoint)MulticastAddress, x);
        }
Exemplo n.º 35
0
 /// <summary>
 /// Instantiates a new endpoint with the specified configuration.
 /// </summary>
 public CoAPEndPoint(ICoapConfig config)
     : this(0, config)
 {
 }
Exemplo n.º 36
0
 /// <summary>
 /// Constructs a new token layer.
 /// </summary>
 public TokenLayer(ICoapConfig config)
 {
     if (config.UseRandomTokenStart)
         _counter = new Random().Next();
 }
Exemplo n.º 37
0
 public Matcher(ICoapConfig config)
 {
     _deduplicator = DeduplicatorFactory.CreateDeduplicator(config);
     if (config.UseRandomIDStart)
         _currentID = new Random().Next(1 << 16);
 }
Exemplo n.º 38
0
 static IChannel NewUDPChannel(Int32 port, ICoapConfig config)
 {
     UDPChannel channel = new UDPChannel(port);
     channel.ReceiveBufferSize = config.ChannelReceiveBufferSize;
     channel.SendBufferSize = config.ChannelSendBufferSize;
     channel.ReceivePacketSize = config.ChannelReceivePacketSize;
     return channel;
 }
Exemplo n.º 39
0
 /// <summary>
 /// Constructs a new observe layer.
 /// </summary>
 public ObserveLayer(ICoapConfig config)
 {
     _backoff = config.NotificationReregistrationBackoff;
 }
Exemplo n.º 40
0
 /// <summary>
 /// Constructs a default message deliverer that delivers requests
 /// to the resources rooted at the specified root.
 /// </summary>
 public ServerMessageDeliverer(ICoapConfig config, IResource root)
 {
     _config = config;
     _root = root;
 }
Exemplo n.º 41
0
 /// <summary>
 /// Constructs a new observe layer.
 /// </summary>
 public ObserveLayer(ICoapConfig config)
 {
     _backoff = config.NotificationReregistrationBackoff;
 }
Exemplo n.º 42
0
 /// <summary>
 /// Instantiates a new endpoint with the specified configuration.
 /// </summary>
 public CoAPEndPoint(ICoapConfig config)
     : this(0, config)
 { }
Exemplo n.º 43
0
 /// <summary>
 /// Instantiates a new endpoint with the
 /// specified port and configuration.
 /// </summary>
 public CoAPEndPoint(Int32 port, ICoapConfig config)
     : this(NewUDPChannel(port, config), config)
 { }
Exemplo n.º 44
0
 /// <summary>
 /// Instantiates a new endpoint with the
 /// specified <see cref="System.Net.EndPoint"/> and configuration.
 /// </summary>
 public CoAPEndPoint(System.Net.EndPoint localEP, ICoapConfig config)
     : this(NewUDPChannel(localEP, config), config)
 { }
Exemplo n.º 45
0
 /// <summary>
 /// Instantiates.
 /// </summary>
 /// <param name="config">the config</param>
 public CoapClient(ICoapConfig config)
     : this(null, config)
 { }
Exemplo n.º 46
0
 /// <summary>
 /// Constructs a new reliability layer.
 /// </summary>
 public ReliabilityLayer(ICoapConfig config)
 {
     _config = config;
 }
Exemplo n.º 47
0
 public ObserveNotificationOrderer(ICoapConfig config)
 {
     _config = config;
 }
Exemplo n.º 48
0
 public ObserveNotificationOrderer(ICoapConfig config)
 {
     _config = config;
 }
Exemplo n.º 49
0
 public TransmissionContext(ICoapConfig config, Exchange exchange, Message message, Action<TransmissionContext> retransmit)
 {
     _config = config;
     _exchange = exchange;
     _message = message;
     _retransmit = retransmit;
     _currentTimeout = message.AckTimeout;
     _timer = new Timer();
     _timer.AutoReset = false;
     _timer.Elapsed += timer_Elapsed;
 }
Exemplo n.º 50
0
 public SweepDeduplicator(ICoapConfig config)
 {
     _config = config;
     _timer = new Timer(config.MarkAndSweepInterval);
     _timer.Elapsed += Sweep;
 }
Exemplo n.º 51
0
 /// <summary>
 /// Instantiates.
 /// </summary>
 /// <param name="uri">the Uri of remote resource</param>
 /// <param name="config">the config</param>
 public CoapClient(Uri uri, ICoapConfig config)
 {
     _uri = uri;
     _config = config ?? CoapConfig.Default;
 }
Exemplo n.º 52
0
 static IChannel NewUDPChannel(System.Net.EndPoint localEP, ICoapConfig config)
 {
     UDPChannel channel = new UDPChannel(localEP);
     channel.ReceiveBufferSize = config.ChannelReceiveBufferSize;
     channel.SendBufferSize = config.ChannelSendBufferSize;
     channel.ReceivePacketSize = config.ChannelReceivePacketSize;
     return channel;
 }