コード例 #1
0
 public void Post(Host from, Atom packet)
 {
     EventQueue.Enqueue(new PostEvent(from, packet));
 }
コード例 #2
0
 public PostEvent(Host from, Atom message)
     : base(SourceStreamEventType.Post)
 {
     this.From    = from;
     this.Message = message;
 }
コード例 #3
0
 protected virtual void DoPost(Host from, Atom packet)
 {
 }
コード例 #4
0
 protected override void DoPost(Host from, Atom packet)
 {
 }
コード例 #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()));
 }
コード例 #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;
       }
 }
コード例 #7
0
 protected abstract void DoPost(Host from, Atom packet);
コード例 #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);
     }
       }
 }
コード例 #9
0
 protected override void DoPost(Host from, Atom packet)
 {
   //Do nothing
 }
コード例 #10
0
 public void Post(Host from, Atom packet)
 {
     if (!IsStopped) {
     SyncContext.Post(dummy => {
       DoPost(from, packet);
     }, null);
       }
 }
コード例 #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);
   }
 }
コード例 #12
0
 public void Post(Host from, Atom packet)
 {
   if (IsStopped) return;
   DoPost(from, packet);
 }
コード例 #13
0
		public void Post(Host from, Atom packet)
		{
		}
コード例 #14
0
ファイル: Host.cs プロジェクト: kumaryu/peercaststation
 /// <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();
   }
 }
コード例 #15
0
 protected virtual Task DoPost(Host from, Atom packet, CancellationToken cancel_token)
 {
   return Task.Delay(0);
 }
コード例 #16
0
 protected override void DoPost(Host from, Atom packet)
 {
     if (Downhost!=null && Downhost!=from) {
     Send(packet);
       }
 }
コード例 #17
0
 public void Post(Host from, Atom packet)
 {
   if (isStopped.IsCancellationRequested) return;
   DoPost(from, packet, isStopped.Token);
 }
コード例 #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();
       }
 }
コード例 #19
0
 public void Post(Host from, Atom packet)
 {
     if (!IsStopped) {
     PostAction(() => {
       DoPost(from, packet);
     });
       }
 }
コード例 #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;
       }
 }
コード例 #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);
   }
 }