1 module tagion.gossip.GossipNet; 2 3 import core.time : MonoTime; 4 import std.concurrency; 5 import std.format; 6 import std.string : representation; 7 import tagion.basic.ConsensusExceptions; 8 import tagion.crypto.SecureNet : StdSecureNet; 9 import tagion.crypto.Types : Pubkey; 10 import tagion.gossip.InterfaceNet; 11 import tagion.hashgraph.Event; 12 import tagion.hashgraph.HashGraph; 13 import tagion.hashgraph.HashGraphBasic; 14 import tagion.hibon.Document : Document; 15 16 @safe 17 abstract class StdGossipNet : StdSecureNet, GossipNet { 18 static private shared uint _next_global_id; 19 static private shared uint[immutable(Pubkey)] _node_id_pair; 20 21 uint globalNodeId(immutable(Pubkey) channel) { 22 if (channel in _node_id_pair) { 23 return _node_id_pair[channel]; 24 } 25 else { 26 return setGlobalNodeId(channel); 27 } 28 } 29 30 @trusted 31 static private uint setGlobalNodeId(immutable(Pubkey) channel) { 32 import core.atomic; 33 34 auto result = _next_global_id; 35 _node_id_pair[channel] = _next_global_id; 36 atomicOp!"+="(_next_global_id, 1); 37 return result; 38 } 39 40 this() { 41 super(); 42 } 43 44 static struct Init { 45 uint timeout; 46 uint node_id; 47 uint N; 48 string monitor_ip_address; 49 ushort monitor_port; 50 uint seed; 51 string node_name; 52 } 53 54 protected { 55 ulong _current_time; 56 // HashGraphI _hashgraph; 57 } 58 59 protected Tid _transcript_tid; 60 @property void transcript_tid(Tid tid) 61 @trusted 62 in { 63 assert(_transcript_tid !is _transcript_tid.init, format("%s hash already been set", __FUNCTION__)); 64 } 65 do { 66 _transcript_tid = tid; 67 } 68 69 @property Tid transcript_tid() pure nothrow { 70 return _transcript_tid; 71 } 72 73 protected Tid _scripting_engine_tid; 74 @property void scripting_engine_tid(Tid tid) @trusted 75 in { 76 assert(_scripting_engine_tid !is _scripting_engine_tid.init, format( 77 "%s hash already been set", __FUNCTION__)); 78 } 79 do { 80 _scripting_engine_tid = tid; 81 } 82 83 @property Tid scripting_engine_tid() pure nothrow { 84 return _scripting_engine_tid; 85 } 86 }