public void Post(Host from, Atom packet) { EventQueue.Enqueue(new PostEvent(from, packet)); }
public PostEvent(Host from, Atom message) : base(SourceStreamEventType.Post) { this.From = from; this.Message = message; }
protected virtual void DoPost(Host from, Atom packet) { }
protected override void DoPost(Host from, Atom packet) { }
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())); }
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);
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); } } }
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); } }
protected override async Task DoPost(Host from, Atom packet, CancellationToken cancel_token) { if (Downhost!=null && Downhost!=from) { await Connection.WriteAsync(packet, cancel_token); } }
public void Post(Host from, Atom packet) { if (IsStopped) return; DoPost(from, packet); }
public void Post(Host from, Atom packet) { }
/// <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(); } }
protected virtual Task DoPost(Host from, Atom packet, CancellationToken cancel_token) { return Task.Delay(0); }
protected override void DoPost(Host from, Atom packet) { if (Downhost!=null && Downhost!=from) { Send(packet); } }
public void Post(Host from, Atom packet) { if (isStopped.IsCancellationRequested) return; DoPost(from, packet, isStopped.Token); }
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(); } }
public void Post(Host from, Atom packet) { if (!IsStopped) { PostAction(() => { DoPost(from, packet); }); } }
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; } }
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); } }