mirror of
https://github.com/faragher/RNS_CS_Dev.git
synced 2024-11-28 18:21:03 +01:00
Initial Commit
This commit is contained in:
parent
9313267323
commit
b1f797fbfa
7
Crypto/fernet.cs
Normal file
7
Crypto/fernet.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RNS.Cryptography
|
||||||
|
{
|
||||||
|
public class Fernet
|
||||||
|
{
|
||||||
|
public const int FERNET_OVERHEAD = 48; //Bytes
|
||||||
|
}
|
||||||
|
}
|
46
Identity.cs
Normal file
46
Identity.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||||
|
// C# Port (c) 2023 Michael Faragher / betweentheborders.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// This is considered pre-alpha of a minimum viable product. No warranties are provided and compatibility is not assured.
|
||||||
|
|
||||||
|
namespace RNS
|
||||||
|
{
|
||||||
|
public class Identity
|
||||||
|
{
|
||||||
|
string CURVE = "Curve25519";
|
||||||
|
|
||||||
|
|
||||||
|
const int KEYSIZE = 256 * 2;
|
||||||
|
|
||||||
|
|
||||||
|
public const int FERNET_OVERHEAD = RNS.Cryptography.Fernet.FERNET_OVERHEAD;
|
||||||
|
public const int AES128_BLOCKSIZE = 16; // In bytes
|
||||||
|
int HASHLENGTH = 256; // In bits
|
||||||
|
int SIGLENGTH = KEYSIZE; // In bits
|
||||||
|
|
||||||
|
int NAME_HASH_LENGTH = 80;
|
||||||
|
int TRUNCATED_HASHLENGTH = RNS.Reticulum.TRUNCATED_HASHLENGTH;
|
||||||
|
|
||||||
|
//known_destinations = {} //toDo FixMe
|
||||||
|
}
|
||||||
|
}
|
101
Interfaces/Interface.cs
Normal file
101
Interfaces/Interface.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||||
|
// C# Port (c) 2023 Michael Faragher / betweentheborders.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// This is considered pre-alpha of a minimum viable product. No warranties are provided and compatibility is not assured.
|
||||||
|
|
||||||
|
namespace RNS
|
||||||
|
{
|
||||||
|
public class Interface
|
||||||
|
{
|
||||||
|
public bool IN = false;
|
||||||
|
public bool OUT = false;
|
||||||
|
public bool FWD = false;
|
||||||
|
public bool RPT = false;
|
||||||
|
public string name = "";
|
||||||
|
|
||||||
|
// Interface mode definitions
|
||||||
|
const byte MODE_FULL = 0x01;
|
||||||
|
const byte MODE_POINT_TO_POINT = 0x02;
|
||||||
|
const byte MODE_ACCESS_POINT = 0x03;
|
||||||
|
const byte MODE_ROAMING = 0x04;
|
||||||
|
const byte MODE_BOUNDARY = 0x05;
|
||||||
|
const byte MODE_GATEWAY = 0x06;
|
||||||
|
|
||||||
|
// Which interface modes a Transport Node
|
||||||
|
// should actively discover paths for.
|
||||||
|
byte[] DISCOVER_PATHS_FOR = {MODE_ACCESS_POINT, MODE_GATEWAY};
|
||||||
|
|
||||||
|
|
||||||
|
int rxb;
|
||||||
|
int txb;
|
||||||
|
bool online;
|
||||||
|
|
||||||
|
public CallbackClass Callbacks;
|
||||||
|
|
||||||
|
int ANNOUNCE_CAP;
|
||||||
|
public int ifac_size;
|
||||||
|
//List<>
|
||||||
|
|
||||||
|
public Interface()
|
||||||
|
{
|
||||||
|
rxb = 0;
|
||||||
|
txb = 0;
|
||||||
|
online = false;
|
||||||
|
if(ANNOUNCE_CAP == 0)
|
||||||
|
{
|
||||||
|
ANNOUNCE_CAP = RNS.Reticulum.ANNOUNCE_CAP;
|
||||||
|
}
|
||||||
|
Callbacks = new CallbackClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CallbackArgs : EventArgs
|
||||||
|
{
|
||||||
|
public byte[] Message { get; private set; }
|
||||||
|
public RNS.Interface Interface { get; private set; }
|
||||||
|
public CallbackArgs(byte[] _message, RNS.Interface _interface)
|
||||||
|
{
|
||||||
|
Message = _message;
|
||||||
|
Interface = _interface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CallbackClass
|
||||||
|
{
|
||||||
|
//public delegate void CallbackEventHandler(object sender, CallbackArgs args);
|
||||||
|
public event EventHandler<CallbackArgs>? CallbackEventHandler;
|
||||||
|
public void Process_Inbound(byte[] _message, RNS.Interface _interface)
|
||||||
|
{
|
||||||
|
OnCallback(new CallbackArgs(_message, _interface));
|
||||||
|
}
|
||||||
|
protected virtual void OnCallback(CallbackArgs e)
|
||||||
|
{
|
||||||
|
EventHandler<CallbackArgs>? handler = CallbackEventHandler;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
handler(this, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
63
Link.cs
Normal file
63
Link.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||||
|
// C# Port (c) 2023 Michael Faragher / betweentheborders.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// This is considered pre-alpha of a minimum viable product. No warranties are provided and compatibility is not assured.
|
||||||
|
|
||||||
|
namespace RNS
|
||||||
|
{
|
||||||
|
public class Link
|
||||||
|
{
|
||||||
|
|
||||||
|
//object CURVE = RNS.Identity.CURVE; //ToDo FixMe
|
||||||
|
const int ECPUBSIZE = 32 + 32;
|
||||||
|
const int KEYSIZE = 32;
|
||||||
|
|
||||||
|
const int MDU = ((RNS.Reticulum.MTU - RNS.Reticulum.IFAC_MIN_SIZE - RNS.Reticulum.HEADER_MINSIZE - RNS.Identity.FERNET_OVERHEAD) / RNS.Identity.AES128_BLOCKSIZE) * RNS.Identity.AES128_BLOCKSIZE - 1;
|
||||||
|
|
||||||
|
const int ESTABLISHMENT_TIMEOUT_PER_HOP = RNS.Reticulum.DEFAULT_PER_HOP_TIMEOUT;
|
||||||
|
|
||||||
|
const int TRAFFIC_TIMEOUT_FACTOR = 6;
|
||||||
|
const int KEEPALIVE_TIMEOUT_FACTOR = 4;
|
||||||
|
|
||||||
|
const int STALE_GRACE = 2;
|
||||||
|
|
||||||
|
const int KEEPALIVE = 360;
|
||||||
|
|
||||||
|
public const int STALE_TIME = 2 * KEEPALIVE;
|
||||||
|
|
||||||
|
const byte PENDING = 0x00;
|
||||||
|
const byte HANDSHAKE = 0x01;
|
||||||
|
const byte ACTIVE = 0x02;
|
||||||
|
const byte STALE = 0x03;
|
||||||
|
const byte CLOSED = 0x04;
|
||||||
|
|
||||||
|
const byte TIMEOUT = 0x01;
|
||||||
|
const byte INITIATOR_CLOSED = 0x02;
|
||||||
|
const byte DESTINATION_CLOSED = 0x03;
|
||||||
|
|
||||||
|
const byte ACCEPT_NONE = 0x00;
|
||||||
|
const byte ACCEPT_APP = 0x01;
|
||||||
|
const byte ACCEPT_ALL = 0x02;
|
||||||
|
byte[] resource_strategies = {ACCEPT_NONE, ACCEPT_APP, ACCEPT_ALL};
|
||||||
|
}
|
||||||
|
}
|
92
Program.cs
Normal file
92
Program.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||||
|
// C# Port (c) 2023 Michael Faragher / betweentheborders.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// This is considered pre-alpha of a minimum viable product. No warranties are provided and compatibility is not assured.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
byte[] sideband_fb_data = new byte[] {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x07, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
|
||||||
|
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc1, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
|
||||||
|
0x00, 0x1f, 0xff, 0xff, 0xfc, 0x1f, 0xf8, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x07, 0xfc, 0x00,
|
||||||
|
0x00, 0x7f, 0xff, 0xff, 0xe0, 0x03, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc1, 0x01, 0xff, 0x00,
|
||||||
|
0x01, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0x00, 0x01, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0x80,
|
||||||
|
0x03, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xc1, 0x07, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xe0,
|
||||||
|
0x07, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xe0, 0x0f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf0,
|
||||||
|
0x0f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf0, 0x1f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xf8,
|
||||||
|
0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xf8,
|
||||||
|
0x3f, 0xff, 0xff, 0xc1, 0x20, 0x03, 0xff, 0xfc, 0x3f, 0xf8, 0x3f, 0x80, 0xf0, 0x07, 0xff, 0xfc,
|
||||||
|
0x3f, 0xe0, 0x0f, 0x01, 0xfc, 0x1f, 0xff, 0xfc, 0x7f, 0xc1, 0x04, 0x07, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7f, 0x80, 0x00, 0x0f, 0xfe, 0x3f, 0xff, 0xfe, 0x7f, 0x00, 0x00, 0x3f, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7f, 0x00, 0x00, 0x7f, 0xfe, 0x3f, 0xff, 0xfe, 0x7e, 0x00, 0x00, 0xff, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7e, 0x00, 0x00, 0xff, 0xfe, 0x3f, 0xff, 0xfe, 0x7e, 0x00, 0x00, 0xff, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7e, 0x00, 0x00, 0xff, 0xfe, 0x3f, 0xff, 0xfe, 0x7e, 0x00, 0x00, 0xff, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7f, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0xff, 0xfe, 0x7f, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7f, 0x80, 0x03, 0xff, 0xfe, 0x3f, 0xff, 0xfe, 0x7f, 0xc0, 0x07, 0xff, 0xfe, 0x3f, 0xff, 0xfe,
|
||||||
|
0x7f, 0xe0, 0x0f, 0xff, 0xfc, 0x1f, 0xff, 0xfe, 0x3f, 0xf8, 0x3f, 0xff, 0xf0, 0x07, 0xff, 0xfc,
|
||||||
|
0x3f, 0xff, 0xff, 0xff, 0xe0, 0x03, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xfc,
|
||||||
|
0x3f, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0xf8, 0x1f, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0xf8,
|
||||||
|
0x1f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf8, 0x0f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf0,
|
||||||
|
0x0f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf0, 0x07, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xe0,
|
||||||
|
0x07, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xe0, 0x03, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0xc1,
|
||||||
|
0x01, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0x80, 0x00, 0xff, 0xff, 0xff, 0xc0, 0x01, 0xff, 0x00,
|
||||||
|
0x00, 0xff, 0xff, 0xff, 0xe0, 0x03, 0xff, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x07, 0xfe, 0x00,
|
||||||
|
0x00, 0x3f, 0xff, 0xff, 0xfc, 0x1f, 0xfc, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00,
|
||||||
|
0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc1, 0x00,
|
||||||
|
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
//Modify the COM port and broadcast specifications as required
|
||||||
|
RNode.RNodeInterface R = new RNode.RNodeInterface(new RNS.Transport(), "RNS Test Node", "COM6",915000000,125000,2,8,5,false);
|
||||||
|
|
||||||
|
void TestCallback(object sender, RNS.Interface.CallbackArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Got a packet: ");
|
||||||
|
foreach(byte b in e.Message)
|
||||||
|
{
|
||||||
|
Console.Write(b.ToString("X")+" ");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
R.Callbacks.CallbackEventHandler += TestCallback;
|
||||||
|
|
||||||
|
Console.WriteLine("Return to send packet. Q then return to quit.");
|
||||||
|
R.EnableBacklight();
|
||||||
|
R.Enable_External_Framebuffer();
|
||||||
|
R.Display_Image(sideband_fb_data);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var Dummy = Console.ReadLine();
|
||||||
|
if (Dummy == "q") break;
|
||||||
|
R.Send(new byte[] { 0x47, 0x6f, 0x6f, 0x64, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74 });
|
||||||
|
}
|
||||||
|
Console.WriteLine("Terminating...");
|
||||||
|
R.Disable_External_Framebuffer();
|
||||||
|
R.DisableBacklight();
|
||||||
|
R.CloseRadio();
|
1353
RNodeInterface.cs
Normal file
1353
RNodeInterface.cs
Normal file
File diff suppressed because it is too large
Load Diff
202
Reticulum.cs
Normal file
202
Reticulum.cs
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||||
|
// C# Port (c) 2023 Michael Faragher / betweentheborders.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// This is considered pre-alpha of a minimum viable product. No warranties are provided and compatibility is not assured.
|
||||||
|
|
||||||
|
namespace RNS
|
||||||
|
{
|
||||||
|
public class Reticulum
|
||||||
|
{
|
||||||
|
public const int MTU = 500;
|
||||||
|
const int MAX_QUEUED_ANNOUNCES = 16384;
|
||||||
|
const int QUEUED_ANNOUNCE_LIFE = 60 * 60 * 24;
|
||||||
|
|
||||||
|
public const int ANNOUNCE_CAP = 2;
|
||||||
|
|
||||||
|
|
||||||
|
const int MINIMUM_BITRATE = 500;
|
||||||
|
|
||||||
|
|
||||||
|
public const int DEFAULT_PER_HOP_TIMEOUT = 6;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public const int TRUNCATED_HASHLENGTH = 128;
|
||||||
|
|
||||||
|
public const int HEADER_MINSIZE = 2 + 1 + (TRUNCATED_HASHLENGTH / 8) * 1;
|
||||||
|
public const int HEADER_MAXSIZE = 2 + 1 + (TRUNCATED_HASHLENGTH / 8) * 2;
|
||||||
|
public const int IFAC_MIN_SIZE = 1;
|
||||||
|
byte[] IFAC_SALT = ParseHexToByteArray("adf54d882c9a9b80771eb4995d702d4a3e733391b2a0f53f416d9f907e55cff8");
|
||||||
|
|
||||||
|
int MDU = MTU - HEADER_MAXSIZE - IFAC_MIN_SIZE;
|
||||||
|
|
||||||
|
int RESOURCE_CACHE = 24 * 60 * 60;
|
||||||
|
int JOB_INTERVAL = 5 * 60;
|
||||||
|
int CLEAN_INTERVAL = 15 * 60;
|
||||||
|
int PERSIST_INTERVAL = 60 * 60 * 12;
|
||||||
|
|
||||||
|
// router = None
|
||||||
|
// config = None //ToDo FixMe
|
||||||
|
|
||||||
|
// # The default configuration path will be expanded to a directory
|
||||||
|
//# named ".reticulum" inside the current users home directory
|
||||||
|
public string userdir = Environment.SpecialFolder.UserProfile.ToString();
|
||||||
|
string configdir = "";
|
||||||
|
string configpath = "";
|
||||||
|
string storagepath = "";
|
||||||
|
string cachepath = "";
|
||||||
|
|
||||||
|
|
||||||
|
public static byte[] ParseHexToByteArray(string S)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[S.Length / 2];
|
||||||
|
int i = 0;
|
||||||
|
while (i < buffer.Length)
|
||||||
|
{
|
||||||
|
buffer[i] = byte.Parse(S.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Packet
|
||||||
|
{
|
||||||
|
byte HeaderA;
|
||||||
|
byte Hops;
|
||||||
|
byte Context;
|
||||||
|
byte[] AddressA = new byte[16];
|
||||||
|
byte[] AddressB = new byte[16];
|
||||||
|
byte[] DataBuffer = new byte[465];
|
||||||
|
byte[] Data;
|
||||||
|
byte[] IFAC = new byte[64];
|
||||||
|
byte PropagationType;
|
||||||
|
byte DestinationType;
|
||||||
|
byte PacketType;
|
||||||
|
int DataLength;
|
||||||
|
bool TypeTwoHeader;
|
||||||
|
const byte IFAC_Header = 0b10000000;
|
||||||
|
const byte Header_Type_Header = 0b01000000;
|
||||||
|
const byte Propagation_Type_Header = 0b00110000;
|
||||||
|
const byte Destination_Type_Header = 0b00001100;
|
||||||
|
const byte Packet_Type_Header = 0b00000011;
|
||||||
|
bool IFAC_Flag;
|
||||||
|
|
||||||
|
int Position;
|
||||||
|
public Packet(byte[] Payload, Interface Inter)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
HeaderA = Payload[0];
|
||||||
|
Hops = Payload[1];
|
||||||
|
|
||||||
|
Position = 2;
|
||||||
|
|
||||||
|
IFAC_Flag = ((HeaderA & IFAC_Header) == 0b10000000) ? true : false;
|
||||||
|
TypeTwoHeader = ((HeaderA & Header_Type_Header) == 0b01000000) ? true : false;
|
||||||
|
PropagationType = (byte)((HeaderA & Propagation_Type_Header) >> 4);
|
||||||
|
DestinationType = (byte)((HeaderA & Destination_Type_Header) >> 2);
|
||||||
|
PacketType = (byte)(HeaderA & Packet_Type_Header);
|
||||||
|
|
||||||
|
if (IFAC_Flag)
|
||||||
|
{
|
||||||
|
if (Inter.ifac_size > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Inter.ifac_size; i++)
|
||||||
|
{
|
||||||
|
IFAC[i] = Payload[Position];
|
||||||
|
Position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
AddressA[i] = Payload[Position];
|
||||||
|
Position++;
|
||||||
|
}
|
||||||
|
if (TypeTwoHeader)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
AddressB[i] = Payload[Position];
|
||||||
|
Position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Context = Payload[Position];
|
||||||
|
Position++;
|
||||||
|
DataLength = Payload.Length - Position;
|
||||||
|
Data = new byte[DataLength];
|
||||||
|
for(int i = 0; i < DataLength; i++)
|
||||||
|
{
|
||||||
|
Data[i] = Payload[Position];
|
||||||
|
Position++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void Verbose()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Packet contents:");
|
||||||
|
Console.WriteLine("IFAC: "+IFAC_Flag.ToString());
|
||||||
|
if (IFAC_Flag) {
|
||||||
|
Console.WriteLine(" Length: "+IFAC.Length.ToString());
|
||||||
|
Console.WriteLine(" "+IFAC.ToString());
|
||||||
|
}
|
||||||
|
string buffer = TypeTwoHeader ? "2" : "1";
|
||||||
|
Console.WriteLine("Header Type: "+buffer);
|
||||||
|
Console.WriteLine("Propagation Type: "+PropagationType.ToString()+" ("+Transport.PropagationType[PropagationType]+")");
|
||||||
|
Console.WriteLine("Destination Type: " + DestinationType.ToString() + " ("+Transport.DestinationType[DestinationType]+")");
|
||||||
|
Console.WriteLine("Packet Type: " + PacketType.ToString() + " (" + Transport.PacketType[PacketType] + ")");
|
||||||
|
Console.WriteLine("Hops: " + Hops);
|
||||||
|
Console.Write("Address: ");
|
||||||
|
foreach(byte B in AddressA)
|
||||||
|
{
|
||||||
|
Console.Write(B.ToString("X") + " ");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
if (TypeTwoHeader)
|
||||||
|
{
|
||||||
|
Console.Write("Address 2: ");
|
||||||
|
foreach (byte B in AddressB)
|
||||||
|
{
|
||||||
|
Console.Write(B.ToString("X") + " ");
|
||||||
|
}
|
||||||
|
Console.WriteLine() ;
|
||||||
|
}
|
||||||
|
Console.WriteLine("Context: " + Context.ToString("X"));
|
||||||
|
Console.WriteLine("Data Length: " + DataLength);
|
||||||
|
Console.Write("Data Content: ");
|
||||||
|
foreach(byte B in Data)
|
||||||
|
{
|
||||||
|
Console.Write(B.ToString("X")+" ");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("End packet");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
128
Transport.cs
Normal file
128
Transport.cs
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||||
|
// C# Port (c) 2023 Michael Faragher / betweentheborders.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
// This is considered pre-alpha of a minimum viable product. No warranties are provided and compatibility is not assured.
|
||||||
|
|
||||||
|
namespace RNS
|
||||||
|
{
|
||||||
|
public class Transport
|
||||||
|
{
|
||||||
|
const byte BROADCAST = 0x00;
|
||||||
|
const byte TRANSPORT = 0x01;
|
||||||
|
const byte RELAY = 0x02;
|
||||||
|
const byte TUNNEL = 0x03;
|
||||||
|
byte[] types = {BROADCAST, TRANSPORT, RELAY, TUNNEL};
|
||||||
|
static public Dictionary<byte,string> PropagationType = new Dictionary<byte,string>() { { 0x00, "Broadcast" }, { 0x01, "Transport" }, { 0x02,"Relay"},{ 0x03, "Tunnel" } };
|
||||||
|
|
||||||
|
static public Dictionary<byte, string> DestinationType = new Dictionary<byte, string>() { {0x00,"Single" },{0x01,"Group" },{0x02,"Plain" },{0x03,"link" } };
|
||||||
|
|
||||||
|
static public Dictionary<byte, string> PacketType = new Dictionary<byte, string>() { { 0x00, "Data" }, { 0x01, "announce" }, { 0x02, "Link Request" }, { 0x03, "Proof" } };
|
||||||
|
|
||||||
|
const byte REACHABILITY_UNREACHABLE = 0x00;
|
||||||
|
const byte REACHABILITY_DIRECT = 0x01;
|
||||||
|
const byte REACHABILITY_TRANSPORT = 0x02;
|
||||||
|
|
||||||
|
string APP_NAME = "rnstransport";
|
||||||
|
|
||||||
|
int PATHFINDER_M = 128; //Maximum amount of hops that Reticulum will transport a packet.
|
||||||
|
|
||||||
|
|
||||||
|
int PATHFINDER_R = 1; // Retransmit retries
|
||||||
|
int PATHFINDER_G = 5; // Retry grace period
|
||||||
|
float PATHFINDER_RW = 0.5f; // Random window for announce rebroadcast
|
||||||
|
int PATHFINDER_E = 60 * 60 * 24 * 7; // Path expiration of one week
|
||||||
|
int AP_PATH_TIME = 60 * 60 * 24; // Path expiration of one day for Access Point paths
|
||||||
|
int ROAMING_PATH_TIME = 60 * 60 * 6; // Path expiration of 6 hours for Roaming paths
|
||||||
|
|
||||||
|
// TODO: Calculate an optimal number for this in
|
||||||
|
// various situations
|
||||||
|
int LOCAL_REBROADCASTS_MAX = 2; // How many local rebroadcasts of an announce is allowed
|
||||||
|
|
||||||
|
int PATH_REQUEST_TIMEOUT = 15; // Default timuout for client path requests in seconds
|
||||||
|
float PATH_REQUEST_GRACE = 0.35f; // Grace time before a path announcement is made, allows directly reachable peers to respond first
|
||||||
|
int PATH_REQUEST_RW = 2; // Path request random window
|
||||||
|
int PATH_REQUEST_MI = 5; // Minimum interval in seconds for automated path requests
|
||||||
|
|
||||||
|
float LINK_TIMEOUT = RNS.Link.STALE_TIME * 1.25f;
|
||||||
|
int REVERSE_TIMEOUT = 30 * 60; // Reverse table entries are removed after 30 minutes
|
||||||
|
int DESTINATION_TIMEOUT = 60 * 60 * 24 * 7; // Destination table entries are removed if unused for one week
|
||||||
|
int MAX_RECEIPTS = 1024; // Maximum number of receipts to keep track of
|
||||||
|
int MAX_RATE_TIMESTAMPS = 16; // Maximum number of announce timestamps to keep per destination
|
||||||
|
|
||||||
|
List<Interface> interfaces = new List<Interface>(); // All active interfaces
|
||||||
|
// destinations = [] # All active destinations
|
||||||
|
// pending_links = [] # Links that are being established
|
||||||
|
// active_links = [] # Links that are active
|
||||||
|
// packet_hashlist = [] # A list of packet hashes for duplicate detection
|
||||||
|
// receipts = [] # Receipts of all outgoing packets for proof processing
|
||||||
|
|
||||||
|
// # TODO: "destination_table" should really be renamed to "path_table"
|
||||||
|
// # Notes on memory usage: 1 megabyte of memory can store approximately
|
||||||
|
// # 55.100 path table entries or approximately 22.300 link table entries.
|
||||||
|
|
||||||
|
// announce_table = { } # A table for storing announces currently waiting to be retransmitted
|
||||||
|
// destination_table = {} # A lookup table containing the next hop to a given destination
|
||||||
|
// reverse_table = {} # A lookup table for storing packet hashes used to return proofs and replies
|
||||||
|
// link_table = {} # A lookup table containing hops for links
|
||||||
|
// held_announces = {} # A table containing temporarily held announce-table entries
|
||||||
|
// announce_handlers = [] # A table storing externally registered announce handlers
|
||||||
|
// tunnels = {} # A table storing tunnels to other transport instances
|
||||||
|
// announce_rate_table = {} # A table for keeping track of announce rates
|
||||||
|
// path_requests = {} # A table for storing path request timestamps
|
||||||
|
|
||||||
|
// discovery_path_requests = {} # A table for keeping track of path requests on behalf of other nodes
|
||||||
|
// discovery_pr_tags = [] # A table for keeping track of tagged path requests
|
||||||
|
// max_pr_tags = 32000 # Maximum amount of unique path request tags to remember
|
||||||
|
|
||||||
|
// # Transport control destinations are used
|
||||||
|
// # for control purposes like path requests
|
||||||
|
// control_destinations = []
|
||||||
|
// control_hashes = []
|
||||||
|
|
||||||
|
//# Interfaces for communicating with
|
||||||
|
//# local clients connected to a shared
|
||||||
|
//# Reticulum instance
|
||||||
|
// local_client_interfaces = []
|
||||||
|
|
||||||
|
// local_client_rssi_cache = []
|
||||||
|
// local_client_snr_cache = []
|
||||||
|
// LOCAL_CLIENT_CACHE_MAXSIZE = 512
|
||||||
|
|
||||||
|
// pending_local_path_requests = {}
|
||||||
|
|
||||||
|
// jobs_locked = False
|
||||||
|
// jobs_running = False
|
||||||
|
// job_interval = 0.250
|
||||||
|
// links_last_checked = 0.0
|
||||||
|
// links_check_interval = 1.0
|
||||||
|
// receipts_last_checked = 0.0
|
||||||
|
// receipts_check_interval = 1.0
|
||||||
|
// announces_last_checked = 0.0
|
||||||
|
// announces_check_interval = 1.0
|
||||||
|
// hashlist_maxsize = 1000000
|
||||||
|
// tables_last_culled = 0.0
|
||||||
|
// tables_cull_interval = 5.0
|
||||||
|
|
||||||
|
// identity = None
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user