X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=client.cpp;h=eea41a5e0da43d40b0c468b206158f69198ac1b6;hp=5871da1ed70fb111a85db1bcf278735f64a6b62e;hb=9bb62cbda887f69e570a3ea0fd28b564c5adc2c9;hpb=6942bd4c7da1379565817ae82e6ace259abf4492 diff --git a/client.cpp b/client.cpp index 5871da1..eea41a5 100644 --- a/client.cpp +++ b/client.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include "client.h" @@ -9,6 +9,10 @@ #include "state.pb.h" #include "stream.h" +#ifndef SO_MAX_PACING_RATE +#define SO_MAX_PACING_RATE 47 +#endif + using namespace std; Client::Client(int sock) @@ -32,8 +36,19 @@ Client::Client(int sock) if (getpeername(sock, reinterpret_cast(&addr), &addr_len) == -1) { log_perror("getpeername"); remote_addr = ""; + return; + } + + char buf[INET6_ADDRSTRLEN]; + if (IN6_IS_ADDR_V4MAPPED(&addr.sin6_addr)) { + // IPv4 address, really. + if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == NULL) { + log_perror("inet_ntop"); + remote_addr = ""; + } else { + remote_addr = buf; + } } else { - char buf[INET6_ADDRSTRLEN]; if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == NULL) { log_perror("inet_ntop"); remote_addr = ""; @@ -49,7 +64,7 @@ Client::Client(const ClientProto &serialized, Stream *stream) connect_time(serialized.connect_time()), state(State(serialized.state())), request(serialized.request()), - stream_id(serialized.stream_id()), + url(serialized.url()), stream(stream), header_or_error(serialized.header_or_error()), header_or_error_bytes_sent(serialized.header_or_error_bytes_sent()), @@ -69,6 +84,11 @@ Client::Client(const ClientProto &serialized, Stream *stream) } fwmark = 0; } + if (setsockopt(sock, SOL_SOCKET, SO_MAX_PACING_RATE, &stream->pacing_rate, sizeof(stream->pacing_rate)) == -1) { + if (stream->pacing_rate != ~0U) { + log_perror("setsockopt(SO_MAX_PACING_RATE)"); + } + } } ClientProto Client::serialize() const @@ -79,7 +99,7 @@ ClientProto Client::serialize() const serialized.set_connect_time(connect_time); serialized.set_state(state); serialized.set_request(request); - serialized.set_stream_id(stream_id); + serialized.set_url(url); serialized.set_header_or_error(header_or_error); serialized.set_header_or_error_bytes_sent(serialized.header_or_error_bytes_sent()); serialized.set_stream_pos(stream_pos); @@ -92,7 +112,11 @@ ClientProto Client::serialize() const ClientStats Client::get_stats() const { ClientStats stats; - stats.stream_id = stream_id; + if (url.empty()) { + stats.url = "-"; + } else { + stats.url = url; + } stats.sock = sock; stats.fwmark = fwmark; stats.remote_addr = remote_addr;