Ejemplo n.º 1
0
 public void Post(Host from, Atom packet)
 {
     EventQueue.Enqueue(new PostEvent(from, packet));
 }
Ejemplo n.º 2
0
 public PostEvent(Host from, Atom message)
     : base(SourceStreamEventType.Post)
 {
     this.From    = from;
     this.Message = message;
 }
Ejemplo n.º 3
0
 protected virtual void DoPost(Host from, Atom packet)
 {
 }
Ejemplo n.º 4
0
 protected override void DoPost(Host from, Atom packet)
 {
 }
Ejemplo n.º 5
0
 private Uri CreateHostUri(Host host)
 {
     EndPoint endpoint = IsSiteLocal(host) ? host.LocalEndPoint : host.GlobalEndPoint;
       return new Uri(
     String.Format(
       "pcp://{0}/channel/{1}",
       endpoint.ToString(),
       Channel.ChannelID.ToString("N").ToUpperInvariant()));
 }
Ejemplo n.º 6
0
 private Uri HostToUri(Host host, Guid channel_id)
 {
     if (host==null) return null;
       if (host.GlobalEndPoint!=null) {
     return new Uri(
       String.Format(
     "pcp://{0}:{1}/channel/{2}",
     host.GlobalEndPoint.Address,
     host.GlobalEndPoint.Port,
     channel_id.ToString("N")));
       }
       else if (host.LocalEndPoint!=null) {
     return new Uri(
       String.Format(
     "pcp://{0}:{1}/channel/{2}",
     host.LocalEndPoint.Address,
     host.LocalEndPoint.Port,
     channel_id.ToString("N")));
       }
       else {
     return null;
       }
 }
 protected abstract void DoPost(Host from, Atom packet);
Ejemplo n.º 8
0
 protected override void DoPost(Host from, Atom packet)
 {
     if (uphost!=from) {
     try {
       connection.Send(stream => {
     AtomWriter.Write(stream, packet);
       });
     }
     catch (IOException e) {
       Logger.Info(e);
       Stop(StopReason.ConnectionError);
     }
       }
 }
Ejemplo n.º 9
0
 protected override void DoPost(Host from, Atom packet)
 {
   //Do nothing
 }
 public void Post(Host from, Atom packet)
 {
     if (!IsStopped) {
     SyncContext.Post(dummy => {
       DoPost(from, packet);
     }, null);
       }
 }
Ejemplo n.º 11
0
 protected override async Task DoPost(Host from, Atom packet, CancellationToken cancel_token)
 {
   if (Downhost!=null && Downhost!=from) {
     await Connection.WriteAsync(packet, cancel_token);
   }
 }
Ejemplo n.º 12
0
 public void Post(Host from, Atom packet)
 {
   if (IsStopped) return;
   DoPost(from, packet);
 }
Ejemplo n.º 13
0
		public void Post(Host from, Atom packet)
		{
		}
Ejemplo n.º 14
0
 /// <summary>
 /// 指定されたHostの値でHostBuilderを初期化します
 /// </summary>
 /// <param name="host">初期化元のHost</param>
 public HostBuilder(Host host)
 {
   if (host!=null) {
     SessionID = host.SessionID;
     BroadcastID = host.BroadcastID;
     LocalEndPoint = host.LocalEndPoint;
     GlobalEndPoint = host.GlobalEndPoint;
     RelayCount = host.RelayCount;
     DirectCount = host.DirectCount;
     IsFirewalled = host.IsFirewalled;
     IsTracker = host.IsTracker;
     IsRelayFull = host.IsRelayFull;
     IsDirectFull = host.IsDirectFull;
     IsReceiving = host.IsReceiving;
     IsControlFull = host.IsControlFull;
     Extensions = new List<string>(host.Extensions);
     Extra = new AtomCollection(host.Extra);
   }
   else {
     SessionID = Guid.Empty;
     BroadcastID = Guid.Empty;
     LocalEndPoint = null;
     GlobalEndPoint = null;
     RelayCount = 0;
     DirectCount = 0;
     IsFirewalled = false;
     IsTracker = false;
     IsRelayFull = false;
     IsDirectFull = false;
     IsReceiving = false;
     IsControlFull = false;
     Extensions = new List<string>();
     Extra = new AtomCollection();
   }
 }
Ejemplo n.º 15
0
 protected virtual Task DoPost(Host from, Atom packet, CancellationToken cancel_token)
 {
   return Task.Delay(0);
 }
Ejemplo n.º 16
0
 protected override void DoPost(Host from, Atom packet)
 {
     if (Downhost!=null && Downhost!=from) {
     Send(packet);
       }
 }
Ejemplo n.º 17
0
 public void Post(Host from, Atom packet)
 {
   if (isStopped.IsCancellationRequested) return;
   DoPost(from, packet, isStopped.Token);
 }
Ejemplo n.º 18
0
 protected void OnPCPOleh(Atom atom)
 {
     var rip = atom.Children.GetHeloRemoteIP();
       if (rip!=null) {
     switch (rip.AddressFamily) {
     case AddressFamily.InterNetwork:
       if (PeerCast.GlobalAddress==null ||
       PeerCast.GlobalAddress.GetAddressLocality()<=rip.GetAddressLocality()) {
     PeerCast.GlobalAddress = rip;
       }
       break;
     case AddressFamily.InterNetworkV6:
       if (PeerCast.GlobalAddress6==null ||
       PeerCast.GlobalAddress6.GetAddressLocality()<=rip.GetAddressLocality()) {
     PeerCast.GlobalAddress6 = rip;
       }
       break;
     }
       }
       var port = atom.Children.GetHeloPort();
       if (port.HasValue) {
     PeerCast.IsFirewalled = port.Value==0;
       }
       var sid = atom.Children.GetHeloSessionID();
       if (sid.HasValue) {
     var host = new HostBuilder();
     host.SessionID      = sid.Value;
     host.GlobalEndPoint = RemoteEndPoint;
     uphost = host.ToHost();
       }
 }
Ejemplo n.º 19
0
 public void Post(Host from, Atom packet)
 {
     if (!IsStopped) {
     PostAction(() => {
       DoPost(from, packet);
     });
       }
 }
Ejemplo n.º 20
0
 private bool IsSiteLocal(Host node)
 {
     if (node.GlobalEndPoint!=null) {
     IPAddress global;
     switch (node.GlobalEndPoint.AddressFamily) {
     case AddressFamily.InterNetwork:
       global = PeerCast.GlobalAddress;
       break;
     case AddressFamily.InterNetworkV6:
       global = PeerCast.GlobalAddress6;
       break;
     default:
       throw new ArgumentException("Unsupported AddressFamily", "addr");
     }
     return node.GlobalEndPoint.Equals(global);
       }
       else {
     return true;
       }
 }
Ejemplo n.º 21
0
 protected override async void DoPost(Host from, Atom packet)
 {
   if (uphost==from) return;
   try {
     await connection.Stream.WriteAsync(packet);
   }
   catch (IOException e) {
     Logger.Info(e);
     Stop(StopReason.ConnectionError);
   }
   catch (Exception e) {
     Logger.Info(e);
   }
 }