Ejemplo n.º 1
0
        public virtual RelayRequestResponse RecvRelayRequestResponse()
        {
            RelayRequestResponse response = null;

            if (Recv(s => { response = RelayRequestResponseReader.Read(s); }))
            {
                Logger.Debug("Relay response: {0}", response.StatusCode);
                return(response);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private async Task ProcessRelayRequest(CancellationToken cancel_token)
        {
            Logger.Debug("Sending Relay request: /channel/{0}", Channel.ChannelID.ToString("N"));
            var host_header = remoteHost != null ? $"Host:{remoteHost}\r\n" : "";

            if (remoteHost is DnsEndPoint)
            {
                var dnsendpoint = remoteHost as DnsEndPoint;
                host_header = $"Host:{dnsendpoint.Host}:{dnsendpoint.Port}\r\n";
            }
            var req = System.Text.Encoding.UTF8.GetBytes(
                $"GET /channel/{Channel.ChannelID.ToString("N")} HTTP/1.0\r\n" +
                host_header +
                $"User-Agent:{PeerCast.AgentName}\r\n" +
                $"x-peercast-pcp:{Channel.GetPCPVersion()}\r\n" +
                $"x-peercast-pos:{Channel.ContentPosition}\r\n" +
                $"\r\n"
                );

            try {
                await connection.Stream.WriteAsync(req, cancel_token).ConfigureAwait(false);

                relayResponse = await ReadRequestResponseAsync(connection.Stream, cancel_token).ConfigureAwait(false);

                Logger.Debug("Relay response: {0}", relayResponse.StatusCode);
                if (relayResponse.StatusCode == 200 || relayResponse.StatusCode == 503)
                {
                    return;
                }
                else
                {
                    Logger.Info("Server responses {0} to GET {1}", relayResponse.StatusCode, SourceUri.PathAndQuery);
                    Stop(relayResponse.StatusCode == 404 ? StopReason.OffAir : StopReason.ConnectionError);
                }
            }
            catch (IOException e) {
                Logger.Info(e);
                Stop(StopReason.ConnectionError);
            }
        }
Ejemplo n.º 3
0
        private State WaitRelayResponse()
        {
            relayResponse = null;
            bool longresponse = false;

            try {
                connection.Recv(stream => {
                    longresponse  = stream.Length >= 2048;
                    relayResponse = RelayRequestResponseReader.Read(stream);
                });
            }
            catch (IOException) {
                Stop(StopReason.ConnectionError);
                return(State.Disconnected);
            }
            if (relayResponse != null)
            {
                Logger.Debug("Relay response: {0}", relayResponse.StatusCode);
                if (relayResponse.StatusCode == 200 || relayResponse.StatusCode == 503)
                {
                    return(State.SendingHandshakeRequest);
                }
                else
                {
                    Logger.Error("Server responses {0} to GET {1}", relayResponse.StatusCode, SourceUri.PathAndQuery);
                    Stop(relayResponse.StatusCode == 404 ? StopReason.OffAir : StopReason.UnavailableError);
                    return(State.Disconnected);
                }
            }
            else if (longresponse)
            {
                Stop(StopReason.ConnectionError);
                return(State.Disconnected);
            }
            else
            {
                return(State.WaitingRelayResponse);
            }
        }
Ejemplo n.º 4
0
 private State WaitRelayResponse()
 {
     relayResponse = null;
       bool longresponse = false;
       try {
     connection.Recv(stream => {
       longresponse = stream.Length>=2048;
       relayResponse = RelayRequestResponseReader.Read(stream);
     });
       }
       catch (IOException) {
     Stop(StopReason.ConnectionError);
     return State.Disconnected;
       }
       if (relayResponse!=null) {
       Logger.Debug("Relay response: {0}", relayResponse.StatusCode);
     if (relayResponse.StatusCode==200 || relayResponse.StatusCode==503) {
       return State.SendingHandshakeRequest;
     }
     else {
       Logger.Error("Server responses {0} to GET {1}", relayResponse.StatusCode, SourceUri.PathAndQuery);
       Stop(relayResponse.StatusCode==404 ? StopReason.OffAir : StopReason.UnavailableError);
       return State.Disconnected;
     }
       }
       else if (longresponse) {
     Stop(StopReason.ConnectionError);
     return State.Disconnected;
       }
       else {
     return State.WaitingRelayResponse;
       }
 }
Ejemplo n.º 5
0
 private async Task ProcessRelayRequest(CancellationToken cancel_token)
 {
   Logger.Debug("Sending Relay request: /channel/{0}", Channel.ChannelID.ToString("N"));
   var host_header = remoteHost!=null ? $"Host:{remoteHost}\r\n" : "";
   if (remoteHost is DnsEndPoint) {
     var dnsendpoint = remoteHost as DnsEndPoint;
     host_header = $"Host:{dnsendpoint.Host}:{dnsendpoint.Port}\r\n";
   }
   var req = System.Text.Encoding.UTF8.GetBytes(
     $"GET /channel/{Channel.ChannelID.ToString("N")} HTTP/1.0\r\n" +
     host_header +
     $"User-Agent:{PeerCast.AgentName}\r\n" +
     $"x-peercast-pcp:1\r\n" +
     $"x-peercast-pos:{Channel.ContentPosition}\r\n" +
     $"\r\n"
   );
   try {
     await connection.Stream.WriteAsync(req, cancel_token);
     relayResponse = await ReadRequestResponseAsync(connection.Stream, cancel_token);
     Logger.Debug("Relay response: {0}", relayResponse.StatusCode);
     if (relayResponse.StatusCode==200 || relayResponse.StatusCode==503) {
       return;
     }
     else {
       Logger.Info("Server responses {0} to GET {1}", relayResponse.StatusCode, SourceUri.PathAndQuery);
       Stop(relayResponse.StatusCode==404 ? StopReason.OffAir : StopReason.UnavailableError);
     }
   }
   catch (IOException e) {
     Logger.Info(e);
     Stop(StopReason.ConnectionError);
   }
 }