当前位置: 首页>>代码示例>>C#>>正文


C# AtomCollection.SetHeloSessionID方法代码示例

本文整理汇总了C#中AtomCollection.SetHeloSessionID方法的典型用法代码示例。如果您正苦于以下问题:C# AtomCollection.SetHeloSessionID方法的具体用法?C# AtomCollection.SetHeloSessionID怎么用?C# AtomCollection.SetHeloSessionID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AtomCollection的用法示例。


在下文中一共展示了AtomCollection.SetHeloSessionID方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPCPHelo

 protected virtual void OnPCPHelo(Atom atom)
 {
     var session_id = atom.Children.GetHeloSessionID();
       var oleh = new AtomCollection();
       oleh.SetHeloSessionID(PeerCast.SessionID);
       Send(new Atom(Atom.PCP_OLEH, oleh));
       if (session_id==null) {
     Logger.Info("Helo has no SessionID");
     Stop(StopReason.NotIdentifiedError);
       }
       else {
     Logger.Debug("Helo from {0}", PeerCast.SessionID.ToString("N"));
     Stop(StopReason.None);
       }
 }
开发者ID:j0hn---,项目名称:peercaststation,代码行数:15,代码来源:PCPPongOutputStream.cs

示例2: SendPCPHelo

 private bool SendPCPHelo()
 {
     var helo = new AtomCollection();
       helo.SetHeloAgent(PeerCast.AgentName);
       helo.SetHeloSessionID(PeerCast.SessionID);
       if (PeerCast.IsFirewalled.HasValue) {
     if (PeerCast.IsFirewalled.Value) {
       //Do nothing
     }
     else {
       var listener = PeerCast.FindListener(
     RemoteEndPoint.Address,
     OutputStreamType.Relay | OutputStreamType.Metadata);
       helo.SetHeloPort(listener.LocalEndPoint.Port);
     }
       }
       else {
     var listener = PeerCast.FindListener(
       RemoteEndPoint.Address,
       OutputStreamType.Relay | OutputStreamType.Metadata);
     if (listener!=null) {
       helo.SetHeloPing(listener.LocalEndPoint.Port);
     }
       }
       PCPVersion.SetHeloVersion(helo);
       try {
     connection.Send(stream => {
       AtomWriter.Write(stream, new Atom(Atom.PCP_HELO, helo));
     });
       }
       catch (IOException e) {
     Logger.Info(e);
     Stop(StopReason.ConnectionError);
     return false;
       }
       return true;
 }
开发者ID:peca-dev,项目名称:peercaststation,代码行数:37,代码来源:PCPSourceStream.cs

示例3: PingHost

 protected virtual bool PingHost(IPEndPoint target, Guid remote_session_id)
 {
     Logger.Debug("Ping requested. Try to ping: {0}({1})", target, remote_session_id);
       bool result = false;
       try {
     var client = new System.Net.Sockets.TcpClient();
     client.Connect(target);
     client.ReceiveTimeout = 3000;
     client.SendTimeout    = 3000;
     var stream = client.GetStream();
     var conn = new Atom(Atom.PCP_CONNECT, 1);
     AtomWriter.Write(stream, conn);
     var helo = new AtomCollection();
     helo.SetHeloSessionID(PeerCast.SessionID);
     AtomWriter.Write(stream, new Atom(Atom.PCP_HELO, helo));
     var res = AtomReader.Read(stream);
     if (res.Name==Atom.PCP_OLEH) {
       var session_id = res.Children.GetHeloSessionID();
       if (session_id.HasValue && session_id.Value==remote_session_id) {
     Logger.Debug("Ping succeeded");
     result = true;
       }
       else {
     Logger.Debug("Ping failed. Remote SessionID mismatched");
       }
     }
     AtomWriter.Write(stream, new Atom(Atom.PCP_QUIT, Atom.PCP_ERROR_QUIT));
     stream.Close();
     client.Close();
       }
       catch (InvalidDataException e) {
     Logger.Debug("Ping failed");
     Logger.Debug(e);
       }
       catch (System.Net.Sockets.SocketException e) {
     Logger.Debug("Ping failed");
     Logger.Debug(e);
       }
       catch (EndOfStreamException e) {
     Logger.Debug("Ping failed");
     Logger.Debug(e);
       }
       catch (System.IO.IOException io_error) {
     Logger.Debug("Ping failed");
     Logger.Debug(io_error);
     if (!(io_error.InnerException is System.Net.Sockets.SocketException)) {
       throw;
     }
       }
       return result;
 }
开发者ID:peca-dev,项目名称:peercaststation,代码行数:51,代码来源:PCPOutputStream.cs

示例4: OnPCPHelo

 protected virtual void OnPCPHelo(Atom atom)
 {
     if (Downhost!=null) return;
       Logger.Debug("Helo received");
       var session_id = atom.Children.GetHeloSessionID();
       int remote_port = 0;
       if (session_id!=null) {
     var host = new HostBuilder();
     host.SessionID = session_id.Value;
     var port = atom.Children.GetHeloPort();
     var ping = atom.Children.GetHeloPing();
     if (port!=null) {
       remote_port = port.Value;
     }
     else if (ping!=null) {
       if (IsPingTarget(((IPEndPoint)RemoteEndPoint).Address) &&
       PingHost(new IPEndPoint(((IPEndPoint)RemoteEndPoint).Address, ping.Value), session_id.Value)) {
     remote_port = ping.Value;
       }
       else {
     remote_port = 0;
       }
     }
     else {
       remote_port = 0;
     }
     if (remote_port!=0)  {
       var ip = new IPEndPoint(((IPEndPoint)RemoteEndPoint).Address, remote_port);
       if (host.GlobalEndPoint==null || !host.GlobalEndPoint.Equals(ip)) {
     host.GlobalEndPoint = ip;
       }
     }
     host.IsFirewalled = remote_port==0;
     host.Extra.Update(atom.Children);
     Downhost = host.ToHost();
     UserAgent = atom.Children.GetHeloAgent() ?? UserAgent;
       }
       var oleh = new AtomCollection();
       if (RemoteEndPoint!=null && RemoteEndPoint.AddressFamily==System.Net.Sockets.AddressFamily.InterNetwork) {
     oleh.SetHeloRemoteIP(((IPEndPoint)RemoteEndPoint).Address);
       }
       oleh.SetHeloAgent(PeerCast.AgentName);
       oleh.SetHeloSessionID(PeerCast.SessionID);
       oleh.SetHeloRemotePort(remote_port);
       PCPVersion.SetHeloVersion(oleh);
       Send(new Atom(Atom.PCP_OLEH, oleh));
       if (Downhost==null) {
     Logger.Info("Helo has no SessionID");
     //セッションIDが無かった
     Stop(StopReason.NotIdentifiedError);
       }
       else if ((Downhost.Extra.GetHeloVersion() ?? 0)<1200) {
     Logger.Info("Helo version {0} is too old", Downhost.Extra.GetHeloVersion() ?? 0);
     //クライアントバージョンが無かった、もしくは古すぎ
     Stop(StopReason.BadAgentError);
       }
       else if (IsRelayFull) {
     Logger.Debug("Handshake succeeded {0}({1}) but relay is full", Downhost.GlobalEndPoint, Downhost.SessionID.ToString("N"));
     Stop(StopReason.UnavailableError);
       }
       else {
     Logger.Debug("Handshake succeeded {0}({1})", Downhost.GlobalEndPoint, Downhost.SessionID.ToString("N"));
     Send(new Atom(Atom.PCP_OK, (int)1));
       }
 }
开发者ID:peca-dev,项目名称:peercaststation,代码行数:65,代码来源:PCPOutputStream.cs

示例5: PingHost

 private async Task<bool> PingHost(IPEndPoint target, Guid remote_session_id, CancellationToken cancel_token)
 {
   Logger.Debug("Ping requested. Try to ping: {0}({1})", target, remote_session_id);
   bool result = false;
   try {
     var client = new System.Net.Sockets.TcpClient();
     client.ReceiveTimeout = 2000;
     client.SendTimeout    = 2000;
     await client.ConnectAsync(target.Address, target.Port);
     var stream = client.GetStream();
     await stream.WriteAsync(new Atom(Atom.PCP_CONNECT, 1), cancel_token);
     var helo = new AtomCollection();
     helo.SetHeloSessionID(PeerCast.SessionID);
     await stream.WriteAsync(new Atom(Atom.PCP_HELO, helo), cancel_token);
     var res = await stream.ReadAtomAsync(cancel_token);
     if (res.Name==Atom.PCP_OLEH) {
       var session_id = res.Children.GetHeloSessionID();
       if (session_id.HasValue && session_id.Value==remote_session_id) {
         Logger.Debug("Ping succeeded");
         result = true;
       }
       else {
         Logger.Debug("Ping failed. Remote SessionID mismatched");
       }
     }
     await stream.WriteAsync(new Atom(Atom.PCP_QUIT, Atom.PCP_ERROR_QUIT), cancel_token);
     stream.Close();
     client.Close();
   }
   catch (InvalidDataException e) {
     Logger.Debug("Ping failed");
     Logger.Debug(e);
   }
   catch (System.Net.Sockets.SocketException e) {
     Logger.Debug("Ping failed");
     Logger.Debug(e);
   }
   catch (EndOfStreamException e) {
     Logger.Debug("Ping failed");
     Logger.Debug(e);
   }
   catch (System.IO.IOException io_error) {
     Logger.Debug("Ping failed");
     Logger.Debug(io_error);
     if (!(io_error.InnerException is System.Net.Sockets.SocketException)) {
       throw;
     }
   }
   return result;
 }
开发者ID:kumaryu,项目名称:peercaststation,代码行数:50,代码来源:PCPOutputStream.cs

示例6: OnPCPHelo

 protected virtual void OnPCPHelo(Atom atom)
 {
     if (Downhost!=null) return;
       Logger.Debug("Helo received");
       var session_id = atom.Children.GetHeloSessionID();
       int remote_port = 0;
       if (session_id!=null) {
     var host = new HostBuilder();
     host.SessionID = session_id.Value;
     var port = atom.Children.GetHeloPort();
     var ping = atom.Children.GetHeloPing();
     if (port!=null) {
       remote_port = port.Value;
     }
     else if (ping!=null) {
       if (IsPingTarget(((IPEndPoint)RemoteEndPoint).Address) &&
       PingHost(new IPEndPoint(((IPEndPoint)RemoteEndPoint).Address, ping.Value), session_id.Value)) {
     remote_port = ping.Value;
       }
       else {
     remote_port = 0;
       }
     }
     else {
       remote_port = 0;
     }
     if (remote_port!=0)  {
       var ip = new IPEndPoint(((IPEndPoint)RemoteEndPoint).Address, remote_port);
       if (host.GlobalEndPoint==null || !host.GlobalEndPoint.Equals(ip)) {
     host.GlobalEndPoint = ip;
       }
     }
     host.IsFirewalled = remote_port==0;
     host.Extra.Update(atom.Children);
     Downhost = host.ToHost();
       }
       var oleh = new AtomCollection();
       if (RemoteEndPoint!=null && RemoteEndPoint.AddressFamily==System.Net.Sockets.AddressFamily.InterNetwork) {
     oleh.SetHeloRemoteIP(((IPEndPoint)RemoteEndPoint).Address);
       }
       oleh.SetHeloAgent(PeerCast.AgentName);
       oleh.SetHeloSessionID(PeerCast.SessionID);
       oleh.SetHeloRemotePort(remote_port);
       oleh.SetHeloVersion(PCP_VERSION);
       Send(new Atom(Atom.PCP_OLEH, oleh));
       if (Downhost==null) {
     Logger.Info("Helo has no SessionID");
     //セッションIDが無かった
     Stop(StopReason.NotIdentifiedError);
       }
       else if ((Downhost.Extra.GetHeloVersion() ?? 0)<1200) {
     Logger.Info("Helo version {0} is too old", Downhost.Extra.GetHeloVersion() ?? 0);
     //クライアントバージョンが無かった、もしくは古すぎ
     Stop(StopReason.BadAgentError);
       }
       else if (IsRelayFull) {
     Logger.Debug("Handshake succeeded {0}({1}) but relay is full", Downhost.GlobalEndPoint, Downhost.SessionID.ToString("N"));
     //次に接続するホストを送ってQUIT
     foreach (var node in SelectSourceHosts((IPEndPoint)RemoteEndPoint)) {
       var host_atom = new AtomCollection(node.Extra);
       Atom ip = host_atom.FindByName(Atom.PCP_HOST_IP);
       while (ip!=null) {
     host_atom.Remove(ip);
     ip = host_atom.FindByName(Atom.PCP_HOST_IP);
       }
       Atom port = host_atom.FindByName(Atom.PCP_HOST_PORT);
       while (port!=null) {
     host_atom.Remove(port);
     port = host_atom.FindByName(Atom.PCP_HOST_PORT);
       }
       host_atom.SetHostSessionID(node.SessionID);
       var globalendpoint = node.GlobalEndPoint ?? new IPEndPoint(IPAddress.Any, 0);
       host_atom.AddHostIP(globalendpoint.Address);
       host_atom.AddHostPort(globalendpoint.Port);
       var localendpoint  = node.LocalEndPoint ?? new IPEndPoint(IPAddress.Any, 0);
       host_atom.AddHostIP(localendpoint.Address);
       host_atom.AddHostPort(localendpoint.Port);
       host_atom.SetHostNumRelays(node.RelayCount);
       host_atom.SetHostNumListeners(node.DirectCount);
       host_atom.SetHostChannelID(Channel.ChannelID);
       host_atom.SetHostFlags1(
     (node.IsFirewalled ? PCPHostFlags1.Firewalled : PCPHostFlags1.None) |
     (node.IsTracker ? PCPHostFlags1.Tracker : PCPHostFlags1.None) |
     (node.IsRelayFull ? PCPHostFlags1.None : PCPHostFlags1.Relay) |
     (node.IsDirectFull ? PCPHostFlags1.None : PCPHostFlags1.Direct) |
     (node.IsReceiving ? PCPHostFlags1.Receiving : PCPHostFlags1.None) |
     (node.IsControlFull ? PCPHostFlags1.None : PCPHostFlags1.ControlIn));
       Send(new Atom(Atom.PCP_HOST, host_atom));
       Logger.Debug("Sending Node: {0}({1})", globalendpoint, node.SessionID.ToString("N"));
     }
     Stop(StopReason.UnavailableError);
       }
       else {
     Logger.Debug("Handshake succeeded {0}({1})", Downhost.GlobalEndPoint, Downhost.SessionID.ToString("N"));
     Send(new Atom(Atom.PCP_OK, (int)1));
       }
 }
开发者ID:j0hn---,项目名称:peercaststation,代码行数:97,代码来源:PCPOutputStream.cs

示例7: AnnounceThreadProc

 private void AnnounceThreadProc()
 {
     Logger.Debug("Thread started");
       var host = Uri.DnsSafeHost;
       var port = Uri.Port;
       if (port<0) port = PCPVersion.DefaultPort;
       while (!IsStopped) {
     int next_update = Environment.TickCount;
     posts.Clear();
     try {
       Logger.Debug("Connecting to YP");
       AnnouncingStatus = AnnouncingStatus.Connecting;
       using (var client = new TcpClient(host, port)) {
     remoteEndPoint = (IPEndPoint)client.Client.RemoteEndPoint;
     using (var stream = client.GetStream()) {
       AtomWriter.Write(stream, new Atom(new ID4("pcp\n"), (int)1));
       var helo = new AtomCollection();
       Logger.Debug("Sending Handshake");
       helo.SetHeloAgent(PeerCast.AgentName);
       helo.SetHeloVersion(1218);
       helo.SetHeloSessionID(PeerCast.SessionID);
       helo.SetHeloBCID(PeerCast.BroadcastID);
       if (PeerCast.IsFirewalled.HasValue) {
         if (PeerCast.IsFirewalled.Value) {
           //Do nothing
         }
         else {
           var listener = PeerCast.FindListener(
             ((IPEndPoint)client.Client.RemoteEndPoint).Address,
             OutputStreamType.Relay | OutputStreamType.Metadata);
           if (listener!=null) {
             helo.SetHeloPort(listener.LocalEndPoint.Port);
           }
         }
       }
       else {
         var listener = PeerCast.FindListener(
           ((IPEndPoint)client.Client.RemoteEndPoint).Address,
           OutputStreamType.Relay | OutputStreamType.Metadata);
         if (listener!=null) {
           helo.SetHeloPing(listener.LocalEndPoint.Port);
         }
       }
       AtomWriter.Write(stream, new Atom(Atom.PCP_HELO, helo));
       while (!IsStopped) {
         var atom = AtomReader.Read(stream);
         if (atom.Name==Atom.PCP_OLEH) {
           OnPCPOleh(atom);
           break;
         }
         else if (atom.Name==Atom.PCP_QUIT) {
           Logger.Debug("Handshake aborted by PCP_QUIT ({0})", atom.GetInt32());
           throw new QuitException();
         }
         if (restartEvent.WaitOne(10)) throw new RestartException();
       }
       Logger.Debug("Handshake succeeded");
       AnnouncingStatus = AnnouncingStatus.Connected;
       while (!IsStopped) {
         if (next_update-Environment.TickCount<=0) {
           Logger.Debug("Sending channel info");
           lock (announcingChannels) {
             foreach (var announcing in announcingChannels) {
               PostChannelBcst(announcing.Channel, true);
             }
           }
           next_update = Environment.TickCount+30000;
         }
         if (stream.DataAvailable) {
           Atom atom = AtomReader.Read(stream);
           ProcessAtom(atom);
         }
         lock (posts) {
           foreach (var atom in posts) {
             AtomWriter.Write(stream, atom);
           }
           posts.Clear();
         }
         if (restartEvent.WaitOne(10)) throw new RestartException();
       }
       lock (posts) {
         foreach (var atom in posts) {
           AtomWriter.Write(stream, atom);
         }
         posts.Clear();
       }
       Logger.Debug("Closing connection");
       AtomWriter.Write(stream, new Atom(Atom.PCP_QUIT, Atom.PCP_ERROR_QUIT));
     }
       }
     }
     catch (RestartException) {
       Logger.Debug("Connection retrying");
       AnnouncingStatus = AnnouncingStatus.Connecting;
     }
     catch (BannedException) {
       AnnouncingStatus = AnnouncingStatus.Error;
       Logger.Error("Your BCID is banned");
       break;
     }
//.........这里部分代码省略.........
开发者ID:psjp,项目名称:peercaststation,代码行数:101,代码来源:PCPYellowPageClient.cs

示例8: FindTracker

 public Uri FindTracker(Guid channel_id)
 {
     Logger.Debug("Finding tracker {0} from {1}", channel_id.ToString("N"), Uri);
       var host = Uri.DnsSafeHost;
       var port = Uri.Port;
       Uri res = null;
       if (port<0) port = PCPVersion.DefaultPort;
       try {
     var client = new TcpClient(host, port);
     var stream = client.GetStream();
     var request = System.Text.Encoding.UTF8.GetBytes(
       String.Format("GET /channel/{0} HTTP/1.0\r\n", channel_id.ToString("N")) +
       "x-peercast-pcp:1\r\n" +
       "\r\n");
     stream.Write(request, 0, request.Length);
     var response = ReadResponse(stream);
     var md = System.Text.RegularExpressions.Regex.Match(response, @"^HTTP/1.\d (\d+) ");
     if (md.Success) {
       var status = md.Groups[1].Value;
       switch (status) {
       case "503":
     var helo = new AtomCollection();
     helo.SetHeloAgent(PeerCast.AgentName);
     helo.SetHeloVersion(1218);
     helo.SetHeloSessionID(PeerCast.SessionID);
     helo.SetHeloPort(0);
     AtomWriter.Write(stream, new Atom(Atom.PCP_HELO, helo));
     var hosts = ReadHosts(stream, channel_id);
     res = HostToUri(hosts.FirstOrDefault(h => h.IsTracker), channel_id);
     break;
       case "200":
     //なぜかリレー可能だったのでYP自体をトラッカーとみなしてしまうことにする
     AtomWriter.Write(stream, new Atom(Atom.PCP_QUIT, Atom.PCP_ERROR_QUIT));
     res = Uri;
     break;
       default:
     //エラーだったのでトラッカーのアドレスを貰えず終了
     break;
       }
     }
     AtomWriter.Write(stream, new Atom(Atom.PCP_QUIT, Atom.PCP_ERROR_QUIT));
     client.Close();
       }
       catch (SocketException)
       {
       }
       catch (IOException)
       {
       }
       if (res!=null) {
     Logger.Debug("Tracker found: {0}", res);
       }
       else {
     Logger.Debug("Tracker no found");
       }
       return res;
 }
开发者ID:psjp,项目名称:peercaststation,代码行数:57,代码来源:PCPYellowPageClient.cs

示例9: CreatePCPHelo

 private Atom CreatePCPHelo()
 {
   var helo = new AtomCollection();
   helo.SetHeloAgent(PeerCast.AgentName);
   helo.SetHeloSessionID(PeerCast.SessionID);
   if (PeerCast.IsFirewalled.HasValue) {
     if (PeerCast.IsFirewalled.Value) {
       //Do nothing
     }
     else {
       var listener = PeerCast.FindListener(
         connection.RemoteEndPoint.Address,
         OutputStreamType.Relay | OutputStreamType.Metadata);
       helo.SetHeloPort(listener.LocalEndPoint.Port);
     }
   }
   else {
     var listener = PeerCast.FindListener(
       connection.RemoteEndPoint.Address,
       OutputStreamType.Relay | OutputStreamType.Metadata);
     if (listener!=null) {
       helo.SetHeloPing(listener.LocalEndPoint.Port);
     }
   }
   PCPVersion.SetHeloVersion(helo);
   return new Atom(Atom.PCP_HELO, helo);
 }
开发者ID:kumaryu,项目名称:peercaststation,代码行数:27,代码来源:PCPSourceStream.cs


注:本文中的AtomCollection.SetHeloSessionID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。