static public Node AddNode(Simulator sim, NatTypes type0, NatTypes type1, bool relay) { Node node = sim.AddNode(); NatFactory.AddNat(node.EdgeListenerList, type0); if (relay) { Relay.IRelayOverlap ito = new Relay.SimpleRelayOverlap(); EdgeListener el = new Relay.RelayEdgeListener(node, ito); node.AddEdgeListener(el); el.Start(); } if (type1 != NatTypes.Disabled) { NodeMapping nm = sim.Nodes[node.Address]; int id = nm.ID; string tas = SimulationTransportAddress.GetString(TransportAddress.TAType.SO, id); INat nat = GetNat(TransportAddressFactory.CreateInstance(tas), type1); SimulationEdgeListener el = new SimulationEdgeListener(id, 0, null, true, TransportAddress.TAType.SO, nat); node.AddEdgeListener(el); el.Start(); } return(node); }
public ConnectionTask(NodeMapping node0, NodeMapping node1, bool secure, EventHandler finished) : base(finished) { Node0 = node0; Node1 = node1; Secure = secure; _successful = false; }
private PoolRuleBase[] mapRules(NodeMapping mapping) { var newRules = new PoolRuleBase[_rules.Length]; for (var i = 0; i < _rules.Length; ++i) { newRules[i] = _rules[i].MapNodes(mapping); } return(newRules); }
private void InitNode(AST ast) { if (!NodeMapping.ContainsKey(ast)) { PathConstraints.Add(new HashSet <int>()); NodeMapping.Add(ast, PathConstraints.Count() - 1); } if (!ast.isRoot()) { PathConstraints.Last().UnionWith( ParentConstraints(ast) ); } }
public static async Task WriteNodeHeader(TextWriter writer, NodeMapping nodeMapping) { var isFirst = true; foreach (var mapping in nodeMapping.FieldInfos) { if (!isFirst) await writer.WriteAsync(DELIMITER).ConfigureAwait(false); isFirst = false; if (mapping == nodeMapping.IdField) await writer.WriteAsync(mapping.FieldName).ConfigureAwait(false); else { await WriteFieldInfo(writer, mapping).ConfigureAwait(false); } } await writer.WriteLineAsync().ConfigureAwait(false); }
public static async Task WriteNode(TextWriter writer, NodeMapping nodeMapping, Entity node) { var isFirst = true; foreach (var fieldInfo in nodeMapping.FieldInfos) { if (!isFirst) await writer.WriteAsync(DELIMITER).ConfigureAwait(false); isFirst = false; if (fieldInfo == nodeMapping.IdField) await WriteField(writer, fieldInfo, node.Key).ConfigureAwait(false); else { if (!node.Properties.ContainsKey(fieldInfo.FieldName)) await WriteField(writer, fieldInfo, null).ConfigureAwait(false); else await WriteField(writer, fieldInfo, node.Properties[fieldInfo.FieldName]).ConfigureAwait(false); } } await writer.WriteLineAsync().ConfigureAwait(false); }
public List <dynamic> Execute(NodeMapping nodeMapping = NodeMapping.AsReadOnlyEntity) { List <dynamic> items = new List <dynamic>(); Transaction transaction = Transaction.RunningTransaction; Dictionary <string, object?> parameters = new Dictionary <string, object?>(QueryParameters.Count); foreach (KeyValuePair <string, (object?value, bool isConstant)> queryParameter in QueryParameters) { if (queryParameter.Value.value is null) { parameters.Add(queryParameter.Key, null); } else { parameters.Add(queryParameter.Key, transaction.PersistenceProviderFactory.ConvertToStoredType(queryParameter.Value.GetType(), queryParameter.Value.value)); } } var result = transaction.Run(CompiledQuery.QueryText, parameters); foreach (var row in result) { IDictionary <string, object?> record = new ExpandoObject(); foreach (var field in CompiledQuery.CompiledResultColumns) { object?value; if (row.Values.TryGetValue(field.FieldName, out value) && value is not null) { object?target = (field.ConvertMethod is null) ? value : field.ConvertMethod.Invoke(value); if (target is not null) { if (field.Info.IsAlias) { if (!field.Info.IsList) // RETURNS INode { RawNode node = target.As <RawNode>(); target = (field.MapMethod is null || nodeMapping == NodeMapping.AsRawResult) ? (object?)node : field.MapMethod.Invoke(node, CompiledQuery.QueryText, parameters, nodeMapping); } else if (!field.Info.IsJaggedList) // RETURNS List<INode> { List <object?>?nodeList = ((List <object?>?)target); IList? newList = null; if (nodeList is not null) { newList = (field.MapMethod is null || field.NewList is null || nodeMapping == NodeMapping.AsRawResult) ? new List <RawResult>(nodeList.Count) : field.NewList.Invoke(nodeList.Count); for (int index = 0; index < nodeList.Count; index++) { object?t = nodeList[index]; if (t is null) { newList !.Add(null); } else { RawNode node = t.As <RawNode>(); newList !.Add((field.MapMethod is null || field.NewList is null || nodeMapping == NodeMapping.AsRawResult) ? (object?)node : field.MapMethod.Invoke(node, CompiledQuery.QueryText, parameters, nodeMapping)); } } } target = newList; } else // RETURNS List<List<INode>> { List <List <object?>?>?jaggedNodeList = ((List <List <object?>?>?)target); IList?newJaggedList = null; if (jaggedNodeList is not null) { newJaggedList = (field.MapMethod is null || field.NewList is null || field.NewJaggedList is null || nodeMapping == NodeMapping.AsRawResult) ? new List <List <RawResult?>?>(jaggedNodeList.Count) : field.NewJaggedList.Invoke(jaggedNodeList.Count); for (int mainindex = 0; mainindex < jaggedNodeList.Count; mainindex++) { List <object?>?nodeList = jaggedNodeList[mainindex]; if (nodeList is null) { newJaggedList !.Add(null); } else { IList newList = (field.MapMethod is null || field.NewList is null || nodeMapping == NodeMapping.AsRawResult) ? new List <RawResult>(nodeList.Count) : field.NewList.Invoke(nodeList.Count); for (int subindex = 0; subindex < nodeList.Count; subindex++) { object?t = nodeList[subindex]; if (t is null) { newList.Add(null); } else { RawNode node = t.As <RawNode>(); newList.Add((field.MapMethod is null || field.NewList is null || field.NewJaggedList is null || nodeMapping == NodeMapping.AsRawResult) ? (object?)node : field.MapMethod.Invoke(node, CompiledQuery.QueryText, parameters, nodeMapping)); } } newJaggedList !.Add(newList); } } } target = newJaggedList; } } } record.Add(field.FieldName, target); } else { record.Add(field.FieldName, null); } } items.Add(record); } return(items); }
// adds a node to the pool private static void add_node(bool output) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); Node node = new StructuredNode(address, brunet_namespace); NodeMapping nm = new NodeMapping(); nm.Node = node; nodes.Add((Address) address, nm); nm.Port = rand.Next(1024, 65535); while(TakenPorts.Contains(nm.Port)) { nm.Port = rand.Next(1024, 65535); } EdgeListener el = null; if(edge_type.Equals("function")) { el = new FunctionEdgeListener(nm.Port, 0, null); } else if(edge_type.Equals("tcp")) { el = new TcpEdgeListener(nm.Port); } else if(edge_type.Equals("udp")) { el = new UdpEdgeListener(nm.Port); } node.AddEdgeListener(el); if(!discovery) { ArrayList RemoteTAs = new ArrayList(); for(int i = 0; i < 5 && i < TakenPorts.Count; i++) { int rport = (int) TakenPorts.GetByIndex(rand.Next(0, TakenPorts.Count)); RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet." + edge_type + "://127.0.0.1:" + rport)); } node.RemoteTAs = RemoteTAs; } TakenPorts[nm.Port] = nm.Port; if(dht_enabled) { nm.Dht = new Dht(node, 3); } if(output) { Console.WriteLine("Adding: " + nm.Node.Address); } (new Thread(node.Connect)).Start(); network_size++; }
// adds a node to the pool protected static void add_node(bool output) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); Node node = new StructuredNode(address, brunet_namespace); NodeMapping nm = new NodeMapping(); nm.Node = node; nodes.Add((Address) address, nm); nm.Port = TakenPorts.Count; while(TakenPorts.Contains(nm.Port)) { nm.Port = rand.Next(0, 65535); } TAAuthorizer auth = null; if(broken != 0) { auth = new BrokenTAAuth(broken); } EdgeListener el = new FunctionEdgeListener(nm.Port, 0, auth, true); node.AddEdgeListener(el); if(broken != 0) { el = new TunnelEdgeListener(node); node.AddEdgeListener(el); } ArrayList RemoteTAs = new ArrayList(); for(int i = 0; i < 5 && i < TakenPorts.Count; i++) { int rport = (int) TakenPorts.GetByIndex(rand.Next(0, TakenPorts.Count)); RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet.function://127.0.0.1:" + rport)); } node.RemoteTAs = RemoteTAs; TakenPorts[nm.Port] = nm.Port; if(output) { Console.WriteLine("Adding: " + nm.Node.Address); } node.Connect(); network_size++; }
public ChotaLikeConnection(NodeMapping node0, NodeMapping node1, bool secure, EventHandler finished) : base(node0, node1, secure, finished) { }
public string nextVirtualPath(NodeMapping prevMapping, UserData currUser, string destAddr) { string nextVPI = null; Random random = new Random(); //NodeMapping lastMapping = prevUser.userMappings[prevUser.userMappings.Count() - 1]; if (prevMapping != null) { string outvpi = null; if (prevMapping.outcomingVP == "-") outvpi = prevMapping.incomingVP; else outvpi = prevMapping.outcomingVP; var vpi = from v in currUser.possibleOutVPs where (v.destAddr.Equals(destAddr) && v.vpi.Equals(outvpi)) select v; //ZJEBANE? if (vpi.Any()) nextVPI = outvpi; else { var possiblevpi = from v in currUser.possibleOutVPs where v.destAddr.Equals(destAddr) select v; List<VirtualPath> possiblePaths = possiblevpi.ToList(); nextVPI = (possiblePaths[random.Next(0, possiblePaths.Count() - 1)]).vpi; } } else { var possiblevpi = from v in currUser.possibleOutVPs where v.destAddr.Equals(destAddr) select v; List<VirtualPath> possiblePaths = possiblevpi.ToList(); nextVPI = (possiblePaths[random.Next(0, possiblePaths.Count() - 1)]).vpi; } return nextVPI; }
public string nextVirtualConnection(NodeMapping prevMapping, UserData currUser, string virtualPathId, string destAddr) { string newVCI = null; if (prevMapping != null) { string outvci = null; string outvpi = null; if (prevMapping.outcomingVP == "-" && prevMapping.outcomingVC == "-") { outvci = prevMapping.incomingVC; outvpi = prevMapping.incomingVP; } else { outvci = prevMapping.outcomingVC; outvpi = prevMapping.outcomingVP; } var vpi = from v in currUser.possibleOutVPs where (v.destAddr.Equals(destAddr) && v.vpi.Equals(outvpi)) select v; if(vpi.Any()) { /*foreach (var v in vpi) { newVCI = (v.vci.Count() + 1).ToString(); v.vci.Add(v.vci.Count()+1); }*/ bool found = false; foreach(var v in vpi) { for(int i = 0; i < v.vci.Count(); i++) { if (v.vci[i] == Convert.ToInt32(outvci)) { found = true; } if (found) break; } } if(found) foreach (var v in vpi) { newVCI = (v.vci.Count() + 1).ToString(); v.vci.Add(v.vci.Count() + 1); } else { newVCI = outvci; } } else { newVCI = outvci; //SetText("Error whilst generating new VCI with prevMapping"); } } else { try { var vpi = from v in currUser.possibleOutVPs where (v.destAddr.Equals(destAddr) && v.vpi.Equals(virtualPathId)) select v; foreach (var v in vpi) { newVCI = (v.vci.Count() + 1).ToString(); v.vci.Add(v.vci.Count() + 1); } } catch { SetText("Error whilst generating new VCI without prevMapping"); } } return newVCI; }
// adds a node to the pool protected static void add_node(bool output) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); Node node = new StructuredNode(address, brunet_namespace); NodeMapping nm = new NodeMapping(); nm.Node = node; nodes.Add((Address) address, nm); nm.Port = TakenPorts.Count; while(TakenPorts.Contains(nm.Port)) { nm.Port = rand.Next(0, 65535); } TAAuthorizer auth = null; if(broken != 0) { auth = new BrokenTAAuth(broken); } EdgeListener el = new SimulationEdgeListener(nm.Port, 0, auth, true); if(secure_edges || secure_senders) { byte[] blob = SEKey.ExportCspBlob(true); RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider(); rsa_copy.ImportCspBlob(blob); CertificateMaker cm = new CertificateMaker("United States", "UFL", "ACIS", "David Wolinsky", "*****@*****.**", rsa_copy, address.ToString()); Certificate cert = cm.Sign(CACert, SEKey); CertificateHandler ch = new CertificateHandler(); ch.AddCACertificate(CACert.X509); ch.AddSignedCertificate(cert.X509); BrunetSecurityOverlord so = new BrunetSecurityOverlord(node, rsa_copy, node.Rrm, ch); so.Subscribe(node, null); node.GetTypeSource(SecurityOverlord.Security).Subscribe(so, null); nm.BSO = so; node.HeartBeatEvent += so.Heartbeat; } if(secure_edges) { el = new SecureEdgeListener(el, nm.BSO); } node.AddEdgeListener(el); if(broken != 0) { el = new TunnelEdgeListener(node); node.AddEdgeListener(el); } ArrayList RemoteTAs = new ArrayList(); for(int i = 0; i < 5 && i < TakenPorts.Count; i++) { int rport = (int) TakenPorts.GetByIndex(rand.Next(0, TakenPorts.Count)); RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet.function://127.0.0.1:" + rport)); } node.RemoteTAs = RemoteTAs; TakenPorts[nm.Port] = nm.Port; if(output) { Console.WriteLine("Adding: " + nm.Node.Address); } node.Connect(); network_size++; }
/// <inheritdoc/> protected override PoolRuleBase mapNodes(NodeMapping mapping) { return(new InsertPoolRule(mapping.GetMappedNode(_insertedNode))); }
/// <inheritdoc/> protected override PoolRuleBase mapNodes(NodeMapping mapping) { throw new NotImplementedException(); }
internal static OGM?Map(RawNode node, string cypher, Dictionary <string, object?>?parameters, NodeMapping mappingMode) { object?key = null; if (!node.Properties.TryGetValue(Entity.Key.Name, out key)) { throw new ArgumentException($"The node does not contain key '{Entity.Key.Name}' for entity '{Entity.Name}'."); } if (key is null) { throw new ArgumentException($"The node contains null key '{Entity.Key.Name}' for entity '{Entity.Name}'."); } Transaction trans = Transaction.RunningTransaction; TWrapper?instance = (TWrapper?)trans.GetEntityByKey(Entity.Name, key); if (!(instance is null)) { return(instance); } instance = Transaction.Execute(() => new TWrapper(), EventOptions.GraphEvents); instance.SetKey((TKey)key); OGM ogm = instance as OGM; Dictionary <string, object?> properties = (Dictionary <string, object?>)node.Properties; if (cypher is not null) { Dictionary <string, object?>?customState = null; NodeEventArgs loadingArgs = Entity.RaiseOnNodeLoading(trans, ogm, cypher, parameters, ref customState); NodeEventArgs args = Entity.RaiseOnNodeLoaded(trans, loadingArgs, node.Id, node.Labels, properties); properties = args.Properties !; } if (instance.PersistenceState == PersistenceState.HasUid || instance.PersistenceState == PersistenceState.Loaded) { ogm.SetData(properties); instance.PersistenceState = (mappingMode == NodeMapping.AsWritableEntity) ? PersistenceState.Loaded : PersistenceState.OutOfScope; } return(instance); }
/// <summary> /// wątek odbierający wiadomości z chmury /// </summary> public void receiver() { while (isConnectedToCloud) { BinaryFormatter bf = new BinaryFormatter(); try { SPacket receivedPacket = (Packet.SPacket)bf.Deserialize(networkStream); if (isDebug) SetText("Odczytano:\n" + receivedPacket.ToString()); List<String> _msgList = receivedPacket.getParames(); Address _senderAddr; if (Address.TryParse(receivedPacket.getSrc(), out _senderAddr)) { //gdy logowanie się if (_msgList[0] == "HELLO") { try { string usr = _msgList[1]; Address usrAddr = _senderAddr; bool tempIsOk = true; UserData tempUser = null; //SPRAWDZA CZY TAKI JUZ JEST foreach (UserData ud in userList) { if ((ud.userName == usr || ud.userAddr.ToString() == _senderAddr.ToString())) { tempIsOk = false; tempUser = ud; } } if (tempIsOk) { userList.Add(new UserData(usr, usrAddr, 6, true)); List<string> userNames = new List<string>(); foreach(UserData us in userList) { userNames.Add(us.userName); } BindingSource bs = new BindingSource(); bs.DataSource = userNames; this.Invoke((MethodInvoker)delegate() { selectedUserBox.DataSource = bs; }); SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "OK"); whatToSendQueue.Enqueue(pck); } else { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "NAME_OR_ADDR_TAKEN_BY " + tempUser.userName + " WITH_ADDR " + tempUser.userAddr); whatToSendQueue.Enqueue(pck); } } catch { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "ERROR"); whatToSendQueue.Enqueue(pck); } //gdy żądanie listy klientów } else if (_msgList[0] == "REQ_CONN") { try { foreach (UserData u in userList) { SPacket pck = new SPacket(myAddr.ToString(), u.userAddr.ToString(), "REQ_VPATHS"); whatToSendQueue.Enqueue(pck); } } catch { SetText("Cos walnelo przy żadaniu VP"); } //Z NCC if (_senderAddr.ToString() == NCCAddr.ToString()) { try { string src = _msgList[1]; string dest = _msgList[2]; string connId = _msgList[3]; SPacket pck; var conn = from c in myConnections where c.connId == Convert.ToInt32(connId) select c; if(conn.Any()) { foreach(var c in conn) try { foreach (UserData us in c.connNodes) { foreach (NodeMapping nm in us.userMappings) { try { string msg; if (nm.outcomingAddr == "-" && nm.outcomingVP == "-" && nm.outcomingVC == "-") { msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC; } else { msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC + " " + nm.outcomingAddr + " " + nm.outcomingVP + " " + nm.outcomingVC; } pck = new SPacket(myAddr.ToString(), us.userAddr.ToString(), msg); whatToSendQueue.Enqueue(pck); deleteVirtualConnection(us, nm.outcomingVP, nm.outcomingVC, nm.outcomingAddr); } catch { SetText("Error sending DEL mapping"); } } } } catch { SetText("Error whilst disconnecting existing connection, resto case"); } } currConnection = new ConnectionRequest(src, dest, Convert.ToInt32(connId)); currConnection.prevCCAddr = NCCAddr.ToString(); awaitingConnections.Add(currConnection); //while (awaitingConnections.Count() != 0) //{ //ConnectionRequest temp = awaitingConnections[awaitingConnections.Count() - 1]; pck = new SPacket(myAddr.ToString(), myRCAddr.ToString(), "REQ_ROUTE " + src + " " + dest); whatToSendQueue.Enqueue(pck); //awaitingConnections.Remove(temp); //} } catch { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "REQ_CONN z NCC ma za mało danych?"); whatToSendQueue.Enqueue(pck); } } // Z CC else { try { int connId = Convert.ToInt32(_msgList[1]); string incomingAddr = _msgList[2]; string src = _msgList[3]; string vp = _msgList[4]; string vc = _msgList[5]; string dest = _msgList[6]; SPacket pck; var conn = from c in myConnections where c.connId == Convert.ToInt32(connId) select c; if (conn.Any()) { foreach (var c in conn) try { foreach (UserData us in c.connNodes) { foreach (NodeMapping nm in us.userMappings) { try { string msg; if (nm.outcomingAddr == "-" && nm.outcomingVP == "-" && nm.outcomingVC == "-") { msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC; } else { msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC + " " + nm.outcomingAddr + " " + nm.outcomingVP + " " + nm.outcomingVC; } pck = new SPacket(myAddr.ToString(), us.userAddr.ToString(), msg); whatToSendQueue.Enqueue(pck); deleteVirtualConnection(us, nm.outcomingVP, nm.outcomingVC, nm.outcomingAddr); } catch { SetText("Error sending DEL mapping"); } } } } catch { SetText("Error whilst disconnecting existing connection, resto case"); } } currConnection = new ConnectionRequest(src, dest, connId); currConnection.incomingAddr = incomingAddr; currConnection.inVP = Convert.ToInt32(vp); currConnection.inVC = Convert.ToInt32(vc); currConnection.prevCCAddr = _senderAddr.ToString(); UserData tempUser = null; bool userFound = false; foreach (UserData us in userList) { if (us.userAddr.ToString() == src) { tempUser = us; userFound = true; break; } } if(userFound) { //DODANE ALE NIE WYSŁANE, WYSYŁA DOPIERO PO OTRZYMANIU ROUTE OD RC BO TRZEBA DOKLEIC RESZTE MAPOWANIA tempUser.userMappings.Add(new NodeMapping(incomingAddr, vp, vc, "-", "-", "-", connId)); } pck = new SPacket(myAddr.ToString(), myRCAddr.ToString(), "REQ_ROUTE " + src + " " + dest); whatToSendQueue.Enqueue(pck); } catch { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "REQ_CONN z innego CC ma za mało danych?"); whatToSendQueue.Enqueue(pck); } } } else if(_msgList[0] == "REQ_DISCONN") { int connId = Convert.ToInt32(_msgList[1]); ConnectionRequest connToDis = null; foreach(ConnectionRequest cr in myConnections) { if(cr.connId == connId && cr.active == true) connToDis = cr; } if (connToDis != null) { try { foreach(UserData us in connToDis.connNodes) { foreach(NodeMapping nm in us.userMappings) { try { string msg; if (nm.outcomingAddr == "-" && nm.outcomingVP == "-" && nm.outcomingVC == "-") { msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC; } else { msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC + " " + nm.outcomingAddr + " " + nm.outcomingVP + " " + nm.outcomingVC; } SPacket pck = new SPacket(myAddr.ToString(), us.userAddr.ToString(), msg); whatToSendQueue.Enqueue(pck); deleteVirtualConnection(us, nm.outcomingVP, nm.outcomingVC, nm.outcomingAddr); }catch{ SetText("Error sending DEL mapping"); } } } } catch { SetText("Error whilst disconnecting connection"); } if(connToDis.nextCCAddr != "-") try { SPacket pck = new SPacket(myAddr.ToString(), connToDis.nextCCAddr, "REQ_DISCONN " + connToDis.connId); whatToSendQueue.Enqueue(pck); connToDis.active = false; } catch { SetText("DEL NIE POSZEDL DO NEXTCC"); } else { try { SPacket pck = new SPacket(myAddr.ToString(), NCCAddr.ToString(), "CONN_DISCONN " + connToDis.connId); whatToSendQueue.Enqueue(pck); connToDis.active = false; } catch { SetText("NCC NIE OTRZYMAŁ POTWIERDZENIA DISCONN"); } } } } else if(_msgList[0] == "ROUTE" && _senderAddr.ToString() == myRCAddr.ToString()) { try { UserData prevTempUser = null; for (int i = 1; i < _msgList.Count(); i++ ) { UserData tempUser = null; NodeMapping foundMapping = null; NodeMapping newMapping = null; bool userFound = false; string s = _msgList[i]; foreach(UserData us in userList) { if(us.userAddr.ToString() == s) { tempUser = us; userFound = true; break; } } try { string prev_s = null; string next_s = null; if(i > 0) prev_s = _msgList[i - 1]; if((i+1) < _msgList.Count()) next_s = _msgList[i + 1]; if (!s.Contains('*')) { if (s.Contains(netNum + "." + subNetNum)) { if (userFound) { if (i == 1) { try { if (tempUser.userMappings.Count() != 0) { foreach (NodeMapping nm in tempUser.userMappings) { if (nm.outcomingAddr == "-" && nm.incomingAddr != "-" && nm.toSend == true && nm.callId == currConnection.connId) { foundMapping = nm; } } } } catch { SetText("Something wrong with CC mapping format [error while finding non-complete mapping but mapping is there...]"); } try { if (foundMapping == null && tempUser.userAddr.ToString() != currConnection.destAddr)//DZWONIACY CLIENTX { string newVPI = nextVirtualPath(null, tempUser, next_s); string newVCI = nextVirtualConnection(null, tempUser, newVPI, next_s); newMapping = new NodeMapping(next_s, newVPI, newVCI, "-", "-", "-", currConnection.connId); } else if (foundMapping != null && tempUser.userAddr.ToString() != currConnection.destAddr) //PIERWSZY NODE W NOWEJ PODSIECI { //NodeMapping prevMapping = prevTempUser.userMappings[prevTempUser.userMappings.Count() - 1]; string newVPI = nextVirtualPath(null, tempUser, next_s); string newVCI = nextVirtualConnection(foundMapping, tempUser, newVPI, next_s); //BLEDNE MAPOWANIE 1 W NOWYM NODE DO SPRAWDZENIA!!!! foundMapping.outcomingAddr = next_s; foundMapping.outcomingVP = newVPI; foundMapping.outcomingVC = newVCI; } /*else if (foundMapping != null && tempUser.userAddr.ToString() == currConnection.destAddr)//PIERWSZY NODE W NOWEJ PODSIECI I OSTATNI W POŁĄCZENIU { NodeMapping prevMapping = tempUser.userMappings[tempUser.userMappings.Count() - 1]; //NodeMapping prevMapping = null; //if (prevTempUser.userMappings.Count() > 0) // prevMapping = prevTempUser.userMappings[prevTempUser.userMappings.Count() - 1]; newMapping = new NodeMapping(prev_s, prevMapping.outcomingVP, prevMapping.outcomingVC, "-", "-", "-", currConnection.connId); currConnection.established = true; }*/ } catch(Exception e) { SetText("Error while operating on first ROUTE command member..., Exception " + e.ToString()); } }//KONIEC PIERWSZEGO ADRESU Z ROUTE'A else{ try { if (tempUser.userAddr.ToString() == currConnection.destAddr && !tempUser.userAddr.ToString().Equals(prevTempUser.userAddr.ToString()))//NIE PIERWSZY W ROUTE ALE OSTATNI W POŁĄCZENIU I NIE TEN SAM CO WCZESNIEJ { try { NodeMapping prevMapping = prevTempUser.userMappings[prevTempUser.userMappings.Count() - 1]; string outvpi = null; if (prevMapping.outcomingVP == "-") outvpi = prevMapping.incomingVP; else outvpi = prevMapping.outcomingVP; string outvci = null; if (prevMapping.outcomingVP == "-") outvci = prevMapping.incomingVC; else outvci = prevMapping.outcomingVC; newMapping = new NodeMapping(prev_s, outvpi, outvci, "-", "-", "-", currConnection.connId); currConnection.established = true; } catch(Exception e) { SetText("Error from not first in ROUTE but last in connection, node " + s + ", error: " + e.ToString()); } } else //NODIX GDZIEŚ POMIĘDZY, MA WEJŚCIE I WYJŚCIE { try { NodeMapping prevMapping = prevTempUser.userMappings[prevTempUser.userMappings.Count() - 1]; string newVPI = nextVirtualPath(prevMapping, tempUser, next_s); string newVCI = nextVirtualConnection(prevMapping, tempUser, newVPI, next_s); string outvpi = null; if (prevMapping.outcomingVP == "-") outvpi = prevMapping.incomingVP; else outvpi = prevMapping.outcomingVP; string outvci = null; if (prevMapping.outcomingVP == "-") outvci = prevMapping.incomingVC; else outvci = prevMapping.outcomingVC; newMapping = new NodeMapping(prev_s, outvpi, outvci, next_s, newVPI, newVCI, currConnection.connId); } catch(Exception e) { SetText("Error from transit node: " + s + "Exception e: " + e.ToString()); } } } catch { SetText("Error while operating on not-first members of ROUTE command"); } } try { if (newMapping != null) { tempUser.userMappings.Add(newMapping); prevTempUser = tempUser; } else if (foundMapping != null) { prevTempUser = tempUser; } } catch { SetText("Error while adding newMapping to current NODE"); } currConnection.connNodes.Add(tempUser); //TU ZAMKNIJ } else SetText("Error while operating on ROUTE, there is no connected client having address: " + s); } else { //PIERWSZY NIE Z GWIAZDKA I OSTATNI W OGOLE CZYLI NODE Z NEXT SUBNET currConnection.outNodeAddr = prev_s; currConnection.inNodeAddr = s; NodeMapping prevMapping = prevTempUser.userMappings[prevTempUser.userMappings.Count() - 1]; //string newVPI = nextVirtualPath(prevMapping, tempUser, next_s); //TU_VP currConnection.outVP = Convert.ToInt32(prevMapping.outcomingVP); currConnection.outVC = Convert.ToInt32(prevMapping.outcomingVC); } } else { //TU ZŁAPIE SIĘ TYLKO PIERWSZY Z GWIAZDKA I SUPER BO PRZEKSZTALCAMY GWIAZDKE NA 1 I MAMY NOWY CC DO KTOREGO WYSYLAMY REQ_CONN currConnection.nextCCAddr = s.Replace('*', '1'); break; } } catch(Exception e) { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "Nie wyszło " + e.ToString()); whatToSendQueue.Enqueue(pck); } } //ROZESLIJ WSZELKIE OCZEKUJACE MAPPINGI DO NODE'ÓW sendMappingsToNodes(); if (currConnection.inNodeAddr != "-" && currConnection.outNodeAddr != "-" && currConnection.nextCCAddr != "-") sendToNextSubnet(); if(currConnection.established == true) { SPacket pck = new SPacket(myAddr.ToString(), NCCAddr.ToString(), "CONN_EST " + currConnection.connId); whatToSendQueue.Enqueue(pck); } myConnections.Add(currConnection); } catch(Exception e) { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "ROUTE ERROR PODLACZYŁEŚ JAKIEŚ KLIENTY DEBILU? " + e.ToString()); whatToSendQueue.Enqueue(pck); } } else if (_msgList[0] == "ROUTE_NOT_FOUND") { } else if(_msgList[0] == "RES_VPATHS") { try { receiveVirtualPaths(_msgList, _senderAddr.ToString()); } catch { SetText("Error whilst receiving VPATHS..."); } } else if(_msgList[0] == "DEAD") { string deadAddr = _msgList[1]; List<ConnectionRequest> toRestoreConns = new List<ConnectionRequest>(); foreach(ConnectionRequest cr in myConnections) { foreach(UserData ud in cr.connNodes) { foreach (NodeMapping nm in ud.userMappings) { if (nm.incomingAddr.Equals(deadAddr) || nm.outcomingAddr.Equals(deadAddr)) { var conn = from c in toRestoreConns where c.connId == cr.connId select c; if(!conn.Any()) toRestoreConns.Add(cr); } } } } /*try { foreach (ConnectionRequest cr in toRestoreConns) { foreach (UserData us in cr.connNodes) { foreach (NodeMapping nm in us.userMappings) { try { string msg = "DEL_MAPPING " + nm.incomingAddr + " " + nm.incomingVP + " " + nm.incomingVC + " " + nm.outcomingAddr + " " + nm.outcomingVP + " " + nm.outcomingVC; SPacket pck = new SPacket(myAddr.ToString(), us.userAddr.ToString(), msg); whatToSendQueue.Enqueue(pck); deleteVirtualConnection(us, nm.outcomingVP, nm.outcomingVC, nm.outcomingAddr); } catch { SetText("Error sending DEL mapping in DEAD section"); } } } try { string secParam = null; if(cr.outNodeAddr == "-") { secParam = cr.srcAddr; } else { secParam = cr.inNodeAddr; } SPacket pck; if (cr.prevCCAddr == NCCAddr.ToString()) { // SPacket pck = new SPacket(myAddr.ToString(), myRCAddr.ToString(), "REQ_ROUTE " + cr.srcAddr + " " + secParam); pck = new SPacket(cr.prevCCAddr, myAddr.ToString(), "REQ_CONN " + cr.srcAddr + " " + cr.destAddr + " " + cr.connId); }else{ pck = new SPacket(myAddr.ToString(), cr.prevCCAddr, "REQ_CONN " + cr.connId + " " + cr.outNodeAddr + " " + cr.outVP + " " + cr.outVC + " " + cr.destAddr); } whatToSendQueue.Enqueue(pck); } catch { SetText("Error whilst sending request to RC for restoring in-domain route"); } } } catch { SetText("Error whilst disconnecting connection"); } */ try { foreach (ConnectionRequest cr in toRestoreConns) { try { string msg = null; if(cr.prevCCAddr == "1.0.2") { msg = "REQ_CONN " + cr.srcAddr + " " + cr.destAddr + " " + cr.connId; } else { msg = "REQ_CONN " + cr.connId + " " + cr.incomingAddr + " " + cr.srcAddr + " " + cr.inVP + " " + cr.inVC + " " + cr.destAddr; } SPacket pck = new SPacket(cr.prevCCAddr, myAddr.ToString(), msg); whatToSendQueue.Enqueue(pck); } catch { SetText("Error sending DEL mapping in DEAD section"); } } } catch { SetText("Error whilst connection restoration"); } //SetText(""); //DISCONNECT SASIEDNIE WEZLY ZMAPOWANE //SPacket pck = new SPacket(myAddr.ToString(), "0.0.2", "REQ_CONN ); //whatToSendQueue.Enqueue(pck); } /*else if (_msgList[0] == "REQ_SRC") { int id = Convert.ToInt32(_msgList[1]); var conn = from c in myConnections where c.connId == id select c; if(conn.Any()){ foreach(var c in conn) { SPacket pck = new SPacket(myAddr.ToString(), _senderAddr.ToString(), "MY_SRC " + c.srcAddr); whatToSendQueue.Enqueue(pck); } } }*/ } } catch { SetText("Coś poszło nie tak"); } } }
/// <inheritdoc/> protected override PoolRuleBase mapNodes(NodeMapping mapping) { return(new ConstraintPoolRule(mapping.GetMappedNode(_targetNode), _edges)); }
protected abstract PoolRuleBase mapNodes(NodeMapping mapping);
internal PoolRuleBase MapNodes(NodeMapping mapping) { var mappedRule = mapNodes(mapping); return(mappedRule); }
public SenderReceiver(NodeMapping nm, int max_count) { _nm = nm; _nm.Node.GetTypeSource(testing).Subscribe(this, null); _max_count = max_count; _all_done.Reset(); }
/// <inheritdoc/> protected override PoolRuleBase mapNodes(NodeMapping mapping) { //no nodes can be mapped in Transform rule return(this); }