Skip to content

Commit

Permalink
Remove all of the compiler warnings
Browse files Browse the repository at this point in the history
Remove all of the compiler warnings from the build.
Remove all of the obsolete media types so we better match the IANA registry.
  • Loading branch information
jimsch committed Dec 22, 2019
1 parent a9ddcbb commit 46083a6
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 249 deletions.
1 change: 1 addition & 0 deletions CoAP.Example/CoAP.Server/CoAP.Server.Std10.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
<Compile Remove="Resources\ImageResource.cs" />
</ItemGroup>


Expand Down
1 change: 0 additions & 1 deletion CoAP.Example/CoAP.Server/ExampleServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static void Main(String[] args)
server.Add(new HelloWorldResource("hello"));
server.Add(new FibonacciResource("fibonacci"));
server.Add(new StorageResource("storage"));
server.Add(new ImageResource("image"));
server.Add(new MirrorResource("mirror"));
server.Add(new LargeResource("large"));
server.Add(new CarelessResource("careless"));
Expand Down
6 changes: 6 additions & 0 deletions CoAP.NET/Channel/UDPChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ private void StartMulticastSocket(SocketSet info)
SocketOptionName.AddMembership,
mc);
}
#pragma warning disable 168
catch (SocketException e) {
#pragma warning restore 168
#if LOG_UDP_CHANNEL
_Log.Info(
m => m(
Expand All @@ -252,7 +254,9 @@ private void StartMulticastSocket(SocketSet info)
}
}
}
#pragma warning disable 168
catch (SocketException e) {
#pragma warning restore 168
#if LOG_UDP_CHANNEL
_Log.Info(
m => m($"Start Multicast: Address {info._localEP.Address} had an exception ${e.ToString()}"));
Expand Down Expand Up @@ -285,7 +289,9 @@ private void StartMulticastSocket(SocketSet info)
}
}
}
#pragma warning disable 168
catch (SocketException e) {
#pragma warning restore 168
#if LOG_UDP_CHANNEL
_Log.Info(m => m($"Start Multicast: Address {info._localEP.Address} had an exception ${e.ToString()}"));
#endif
Expand Down
7 changes: 5 additions & 2 deletions CoAP.NET/CoAP.Std10.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<TargetFrameworks>netcoreapp2.0;net462;netstandard2.0</TargetFrameworks>
<PackageId>Com.AugustCellars.CoAP</PackageId>
<Id>Com.AugustCellars.CoAP</Id>
<PackageVersion>1.6.0.0</PackageVersion>
<Version>1.6.0.0</Version>
<PackageVersion>1.7.0.0</PackageVersion>
<Version>1.7.0.0</Version>
<Authors>Jim Schaad</Authors>
<Title>C# Implementation of CoAP</Title>
<Description>An implementation of various CoAP standards. Both client and server sides are included.</Description>
Expand All @@ -22,6 +22,9 @@
This project is built on the CoAP.NET project of smeshlink which in turn is based on Californium. As this project did not seem to be maintained any more and I wanted a version in order to test the newer items that are coming out of the IETF CORE working group, I have captured it and started exanding it.
It is intented primarily for research and verification work.

1.7
- Remove the media types that had been previously marked as obsolete.
- Internal cleanup work.
1.6
- Use cache key fields for matching blockwise transfers.
- Some corrections for blockwise transfers over TCP
Expand Down
2 changes: 2 additions & 0 deletions CoAP.NET/DTLS/DTLSClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ internal class MyTlsAuthentication
{
private readonly TlsContext _mContext;
public EventHandler<TlsEvent> TlsEventHandler;
#if SUPPORT_RPK || SUPPORT_TLS_CWT
private KeySet _serverKeys;
#endif
private TlsKeyPair TlsKey { get; set; }
#if SUPPORT_TLS_CWT
public KeySet CwtTrustKeySet { get; set; }
Expand Down
100 changes: 21 additions & 79 deletions CoAP.NET/DTLS/DTLSClientChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Net.Sockets;
using Com.AugustCellars.CoAP.Channel;
using Com.AugustCellars.CoAP.Log;
using Com.AugustCellars.COSE;
#if SUPPORT_TLS_CWT
using Com.AugustCellars.WebToken;
Expand All @@ -20,65 +21,20 @@ internal class DTLSClientChannel : IChannel
public const Int32 DefaultReceivePacketSize = 4096;

private readonly System.Net.EndPoint _localEndPoint;
private Int32 _receiveBufferSize = DefaultReceivePacketSize;
private Int32 _sendBufferSize;
private Int32 _receivePacketSize;
private readonly int _port;
private UDPChannel _udpChannel;
private readonly TlsKeyPair _userKey;
public KeySet CwtTrustKeySet { get; set; }

public EventHandler<TlsEvent> TlsEventHandler;
private readonly ILogger _log = LogManager.GetLogger(nameof(DTLSClientChannel));

#if false
/// <summary>
/// Create a client only channel and use a randomly assigned port on
/// the client UDP port.
/// </summary>
/// <param name="userKey">Authentication Key</param>
public DTLSClientChannel(OneKey userKey) : this(userKey, 0)
{
}

/// <summary>
/// Create a client only channel and use a given point
/// </summary>
/// <param name="userKey">Authentication Key</param>
/// <param name="port">client side UDP port</param>
public DTLSClientChannel(OneKey userKey, Intint32 port)
{
_port = port;
_userKey = userKey;
}

#endif
public DTLSClientChannel(TlsKeyPair userKey, int port)
{
_port = port;
_userKey = userKey ?? throw new ArgumentNullException(nameof(userKey));
}
#if false
#if SUPPORT_TLS_CWT
public DTLSClientChannel(CWT cwt, OneKey userKey, KeySet cwtTrustKeys, int port)
{
_port = port;
_userKey = userKey;
_userCwt = cwt;
CwtTrustKeySet = cwtTrustKeys;
}
#endif

/// <summary>
/// Create a client only channel and use a given endpoint
/// </summary>
/// <param name="userKey">Authentication Key</param>
/// <param name="ep">client side endpoint</param>
public DTLSClientChannel(OneKey userKey, System.Net.EndPoint ep)
{
_localEndPoint = ep;
_userKey = userKey;
}
#endif

/// <summary>
/// Create a client only channel and use a given endpoint
Expand All @@ -96,36 +52,25 @@ public DTLSClientChannel(TlsKeyPair userKey, System.Net.EndPoint ep)
public event EventHandler<DataReceivedEventArgs> DataReceived;

/// <inheritdoc/>
public System.Net.EndPoint LocalEndPoint {
get =>_udpChannel == null ? (_localEndPoint ?? new IPEndPoint(IPAddress.IPv6Any, _port)) : _udpChannel.LocalEndPoint;
}
public System.Net.EndPoint LocalEndPoint => _udpChannel == null ? (_localEndPoint ?? new IPEndPoint(IPAddress.IPv6Any, _port)) : _udpChannel.LocalEndPoint;

/// <summary>
/// Gets or sets the <see cref="Socket.ReceiveBufferSize"/>.
/// </summary>
public Int32 ReceiveBufferSize {
get => _receiveBufferSize;
set => _receiveBufferSize = value;
}
public int ReceiveBufferSize { get; set; } = DefaultReceivePacketSize;

/// <summary>
/// Gets or sets the <see cref="Socket.SendBufferSize"/>.
/// </summary>
public Int32 SendBufferSize {
get => _sendBufferSize;
set => _sendBufferSize = value;
}
public int SendBufferSize { get; set; }

/// <summary>
/// Gets or sets the size of buffer for receiving packet.
/// The default value is <see cref="DefaultReceivePacketSize"/>.
/// </summary>
public Int32 ReceivePacketSize {
get => _receivePacketSize;
set => _receivePacketSize = value;
}
public int ReceivePacketSize { get; set; }

private Int32 _running;
private int _running;

/// <inheritdoc/>
public bool AddMulticastAddress(IPEndPoint ep)
Expand Down Expand Up @@ -159,12 +104,13 @@ public void Start()
}

/// <summary>
/// Tell the channel to stop processing data cand clean itself up.
/// Tell the channel to stop processing data and clean itself up.
/// </summary>
public void Stop()
{
if (System.Threading.Interlocked.Exchange(ref _running, 0) == 0)
if (System.Threading.Interlocked.Exchange(ref _running, 0) == 0) {
return;
}

lock (_sessionList) {
foreach (DTLSSession session in _sessionList) {
Expand Down Expand Up @@ -228,24 +174,23 @@ public ISession GetSession(System.Net.EndPoint ep)
#endif
session = new DTLSSession(ipEndPoint, DataReceived, _userKey);
#if SUPPORT_TLS_CWT
}
}
#endif

session.TlsEventHandler += OnTlsEvent;
AddSession(session);


session.Connect(_udpChannel);
}
catch {
;
_log.Error("Failed to establish a DTLS session");
}


return session;
}

private void OnTlsEvent(Object o, TlsEvent e)
private void OnTlsEvent(object o, TlsEvent e)
{
EventHandler<TlsEvent> handler = TlsEventHandler;
if (handler != null) {
Expand All @@ -258,6 +203,7 @@ private void OnTlsEvent(Object o, TlsEvent e)
/// Send data through the DTLS channel to other side
/// </summary>
/// <param name="data">Data to be sent</param>
/// <param name="sessionReceive">What session was the request on</param>
/// <param name="ep">Where to send it</param>
public void Send(byte[] data, ISession sessionReceive, System.Net.EndPoint ep)
{
Expand All @@ -270,9 +216,7 @@ public void Send(byte[] data, ISession sessionReceive, System.Net.EndPoint ep)

DTLSSession session = FindSession(ipEndPoint);
if (session == null) {
#if DEBUG
Console.WriteLine("We should have already setup a session");
#endif
_log.Warn("Setup a new session - ");

// Create a new session to send with if we don't already have one

Expand All @@ -282,9 +226,8 @@ public void Send(byte[] data, ISession sessionReceive, System.Net.EndPoint ep)
session.Connect(_udpChannel);
}
else if (session != sessionReceive) {
#if DEBUG
Console.WriteLine("Don't send because the sessions are different");
#endif
_log.Warn("Don't send because the sessions are different");
return;
}

// Queue the data onto the session.
Expand All @@ -293,14 +236,12 @@ public void Send(byte[] data, ISession sessionReceive, System.Net.EndPoint ep)
session.WriteData();
}
catch (Exception e) {
#if DEBUG
Console.WriteLine("Error in DTLSClientChannel Sending - " + e.ToString());
#endif
_log.Error($"Error in DTLSClientChannel Sending - {e}");
throw;
}
}

private void ReceiveData(Object sender, DataReceivedEventArgs e)
private void ReceiveData(object sender, DataReceivedEventArgs e)
{
lock (_sessionList) {
foreach (DTLSSession session in _sessionList) {
Expand Down Expand Up @@ -330,8 +271,9 @@ private DTLSSession FindSession(IPEndPoint ipEndPoint)
lock (_sessionList) {

foreach (DTLSSession session in _sessionList) {
if (session.EndPoint.Equals(ipEndPoint))
if (session.EndPoint.Equals(ipEndPoint)) {
return session;
}
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion CoAP.NET/DTLS/DTLSSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DTLSSession : ISecureSession

private readonly EventHandler<DataReceivedEventArgs> _dataReceived;

private readonly EventHandler<SessionEventArgs> _sessionEvents;
// private readonly EventHandler<SessionEventArgs> _sessionEvents;

public EventHandler<TlsEvent> TlsEventHandler;
#if SUPPORT_TLS_CWT
Expand Down
2 changes: 1 addition & 1 deletion CoAP.NET/Deduplication/SweepDeduplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SweepDeduplicator : IDeduplicator
= new ConcurrentDictionary<Exchange.KeyID, Exchange>();
private Timer _timer;
private readonly ICoapConfig _config;
private int _period;
// private int _period;

public SweepDeduplicator(ICoapConfig config)
{
Expand Down
Loading

0 comments on commit 46083a6

Please sign in to comment.