/// <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)); }
/// <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; }
public CoapObserveRelation(Request request, IEndPoint endpoint, ICoapConfig config) { _config = config; _request = request; _endpoint = endpoint; _orderer = new ObserveNotificationOrderer(config); request.Reregistering += OnReregister; }
/// <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; }
// 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 }
/// <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; }
public CoapObserveRelation(Request request, IEndPoint endpoint, ICoapConfig config) { _config = config; Request = request; _endpoint = endpoint; Orderer = new ObserveNotificationOrderer(config); Request.ObserveRelation = this; request.Reregistering += OnReregister; }
public CoapStack(ICoapConfig config) : this(config.Port, config.TransferBlockSize, config.SequenceTimeout) { #if COAPALL if (config.Spec != null) { _udpLayer.Spec = config.Spec; } #endif }
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); }
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; }
/// <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; }
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; }
/// <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)); }
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; }
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; }
/// <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; }
/// <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; }
public static ICommunicator CreateCommunicator(ICoapConfig config) { if (config.HttpPort > 0) { return(new ProxyCommunicator(config)); } else { return(new CommonCommunicator(config)); } }
public Matcher(ICoapConfig config) { _deduplicator = DeduplicatorFactory.CreateDeduplicator(config); if (config.UseRandomIDStart) { _currentID = new Random().Next(1 << 16); } _tokenLength = config.TokenLength; config.PropertyChanged += PropertyChanged; }
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; }
/// <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; }
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; } }
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 }
/// <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); } }
/// <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); }
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); } }
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++; } }
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(); }
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; } }
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 }
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; } }
/// <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); }
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); }
/// <summary> /// Instantiates a new endpoint with the specified configuration. /// </summary> public CoAPEndPoint(ICoapConfig config) : this(0, config) { }
/// <summary> /// Constructs a new token layer. /// </summary> public TokenLayer(ICoapConfig config) { if (config.UseRandomTokenStart) _counter = new Random().Next(); }
public Matcher(ICoapConfig config) { _deduplicator = DeduplicatorFactory.CreateDeduplicator(config); if (config.UseRandomIDStart) _currentID = new Random().Next(1 << 16); }
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; }
/// <summary> /// Constructs a new observe layer. /// </summary> public ObserveLayer(ICoapConfig config) { _backoff = config.NotificationReregistrationBackoff; }
/// <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; }
/// <summary> /// Instantiates a new endpoint with the /// specified port and configuration. /// </summary> public CoAPEndPoint(Int32 port, ICoapConfig config) : this(NewUDPChannel(port, config), config) { }
/// <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) { }
/// <summary> /// Instantiates. /// </summary> /// <param name="config">the config</param> public CoapClient(ICoapConfig config) : this(null, config) { }
/// <summary> /// Constructs a new reliability layer. /// </summary> public ReliabilityLayer(ICoapConfig config) { _config = config; }
public ObserveNotificationOrderer(ICoapConfig config) { _config = config; }
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; }
public SweepDeduplicator(ICoapConfig config) { _config = config; _timer = new Timer(config.MarkAndSweepInterval); _timer.Elapsed += Sweep; }
/// <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; }
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; }