public IEnumerable<JObject> GetNetwork(Ant ant) { var array = new List<JObject>(); foreach (var network in GetNetwork()) { if (!network.Check(ant)) continue; foreach (var targetAnts in _ants) { if (network.Service1 != targetAnts.GetName() && network.Service2 != targetAnts.GetName()) continue; foreach (var targetAnt in targetAnts.GetAnt()) { if (targetAnt == ant) continue; var obj = new JObject(); obj.Add("ant", targetAnts.GetId()); obj.Add("id", targetAnt.GetId()); obj.Add("host", new JArray(network.GetAddress(targetAnt))); obj.Add("port", targetAnt.GetPort()); array.Add(obj); } } } return array; }
public bool Check(Ant ant) { if (Service1 != ant.GetAnts().GetName() && Service2 != ant.GetAnts().GetName()) return false; foreach (var ip in ant.GetAddress()) { if (Check(ip)) return true; } return false; }
public IEnumerable<byte[]> GetAddress(Ant ant) { if (Service1 != ant.GetAnts().GetName() && Service2 != ant.GetAnts().GetName()) return null; var _list = new List<byte[]>(); foreach (var address in ant.GetAddress()) { if (Check(address)) { _list.Add(address); } } return _list; }
public Ant JoinAnt(IChannel channel, JObject args) { int id = -1; if (_removeAnt.Count != 0) { id = _removeAnt.Dequeue(); } else { id = _maxAnt++; } _ant[id] = new Ant(this, id, args.Value<int>("port")); _ant[id].AddAddress(args.Value<JArray>("host").Values<byte[]>()); _ant[id].AddChannel(channel); return _ant[id]; }
public void StartAnt(Ant ant) { _workEvent.Set(); }