예제 #1
0
        public CoapProtocolAdapter(PiraeusConfig config, IAuthenticator authenticator, IChannel channel, ILogger logger, HttpContext context = null)
        {
            this.context = context;
            this.logger  = logger;
            CoapConfigOptions options    = config.ObserveOption && config.NoResponseOption ? CoapConfigOptions.Observe | CoapConfigOptions.NoResponse : config.ObserveOption ? CoapConfigOptions.Observe : config.NoResponseOption ? CoapConfigOptions.NoResponse : CoapConfigOptions.None;
            CoapConfig        coapConfig = new CoapConfig(authenticator, config.CoapAuthority, options, config.AutoRetry,
                                                          config.KeepAliveSeconds, config.AckTimeoutSeconds, config.AckRandomFactor,
                                                          config.MaxRetransmit, config.NStart, config.DefaultLeisure, config.ProbingRate, config.MaxLatencySeconds);

            coapConfig.IdentityClaimType = config.ClientIdentityNameClaimType;
            coapConfig.Indexes           = config.GetClientIndexes();

            InitializeAuditor(config);

            Channel                = channel;
            Channel.OnClose       += Channel_OnClose;
            Channel.OnError       += Channel_OnError;
            Channel.OnOpen        += Channel_OnOpen;
            Channel.OnReceive     += Channel_OnReceive;
            Channel.OnStateChange += Channel_OnStateChange;
            session                = new CoapSession(coapConfig, context);

            if (Channel.State != ChannelState.Open)
            {
                Channel.OpenAsync().GetAwaiter();
                Channel.ReceiveAsync();
            }
        }
예제 #2
0
 public CoapConfig(IAuthenticator authenticator, string authority,
                   CoapConfigOptions configOptions, bool autoRetry = false,
                   double keepAliveSeconds = 180,
                   double ackTimeout       = 2.0, double ackRandomFactor = 1.5,
                   int maxRetransmit       = 4, int nstart          = 1, double defaultLeisure = 4.0,
                   double probingRate      = 1.0, double maxLatency = 100.0)
 {
     Authenticator   = authenticator;
     Authority       = authority;
     ConfigOptions   = configOptions;
     AutoRetry       = autoRetry;
     KeepAlive       = keepAliveSeconds;
     AckTimeout      = TimeSpan.FromSeconds(ackTimeout);
     AckRandomFactor = ackRandomFactor;
     MaxRetransmit   = maxRetransmit;
     NStart          = nstart;
     DefaultLeisure  = TimeSpan.FromSeconds(defaultLeisure);
     ProbingRate     = probingRate;
     MaxLatency      = TimeSpan.FromSeconds(maxLatency);
 }