Compare commits
No commits in common. "9a00b28279142401a54bbbe5fbf0e629f9799e78" and "bb4da9ea319fda75e1ebd1d7a0c13adbd20178db" have entirely different histories.
9a00b28279
...
bb4da9ea31
@ -23,14 +23,13 @@ make
|
||||
- NAT handling
|
||||
- Multi thread hashing
|
||||
- Read/write timeout in net
|
||||
- Api ratelimit (the other part)
|
||||
- Decode escaping from server
|
||||
- Use a config file
|
||||
- Add newline escape to server
|
||||
- Better field parsing, remove the horrors at code 310
|
||||
- Add myliststats cmd as --stats arg
|
||||
- Add support for compression
|
||||
- Implement session saving between different invocations, and session destroying
|
||||
- Automatically remove found anime from wishlist
|
||||
- Make deleting from mylist possible, with
|
||||
- Name regexes,
|
||||
- If file is not found at a scan
|
||||
|
22
src/api.c
22
src/api.c
@ -55,7 +55,7 @@ static bool api_ka_now = false; /* Are we doing keepalive now? */
|
||||
|
||||
static struct timespec api_last_packet = {0}; /* Last packet time */
|
||||
static int32_t api_packet_count = 0; /* Only increment */
|
||||
//static int32_t api_fast_packet_count = 0; /* Increment or decrement */
|
||||
static int32_t api_fast_packet_count = 0; /* Incremented or decrement */
|
||||
|
||||
static int api_escaped_string(FILE *io, const struct printf_info *info,
|
||||
const void *const *args)
|
||||
@ -314,6 +314,7 @@ enum error api_clock_init()
|
||||
struct timespec ts;
|
||||
memset(&api_last_packet, 0, sizeof(api_last_packet));
|
||||
api_packet_count = 0;
|
||||
api_fast_packet_count = 0;
|
||||
|
||||
if (clock_getres(API_CLOCK, &ts) != 0) {
|
||||
uio_error("Cannot get clock resolution: %s", strerror(errno));
|
||||
@ -435,7 +436,6 @@ void api_free()
|
||||
*/
|
||||
static void api_ratelimit_sent()
|
||||
{
|
||||
api_packet_count++;
|
||||
clock_gettime(API_CLOCK, &api_last_packet);
|
||||
}
|
||||
|
||||
@ -443,25 +443,16 @@ static void api_ratelimit()
|
||||
{
|
||||
struct timespec ts = {0};
|
||||
uint64_t msdiff, mswait;
|
||||
uint64_t msrate = api_packet_count >= API_LONGTERM_PACKETS ?
|
||||
API_SENDWAIT_LONG : API_SENDWAIT;
|
||||
|
||||
/* First of all, the first N packets are unmetered */
|
||||
if (api_packet_count <= API_FREESEND) {
|
||||
uio_debug("This packet is for free! Yay :D (%d/%d)",
|
||||
api_packet_count, API_FREESEND);
|
||||
return;
|
||||
}
|
||||
|
||||
clock_gettime(API_CLOCK, &ts);
|
||||
msdiff = util_timespec_diff(&api_last_packet, &ts);
|
||||
uio_debug("Time since last packet: %ld ms", msdiff);
|
||||
|
||||
if (msdiff >= msrate)
|
||||
if (msdiff >= API_SENDWAIT)
|
||||
return; /* No ratelimiting is needed */
|
||||
|
||||
/* Need ratelimit, so do it here for now */
|
||||
mswait = msrate - msdiff;
|
||||
mswait = API_SENDWAIT - msdiff;
|
||||
uio_debug("Ratelimit is needed, sleeping for %ld ms", mswait);
|
||||
|
||||
MS_TO_TIMESPEC_L(ts, mswait);
|
||||
@ -602,9 +593,8 @@ static enum error api_cmd_auth(const char *uname, const char *pass,
|
||||
char buffer[API_BUFSIZE];
|
||||
long code;
|
||||
size_t res_len = api_send(buffer, snprintf(buffer, sizeof(buffer),
|
||||
"AUTH user=%s&pass=%B&protover=" API_VERSION "&client=caniadd&"
|
||||
"clientver=" PROG_VERSION "&enc=UTF-8", uname, pass),
|
||||
sizeof(buffer));
|
||||
"AUTH user=%s&pass=%B&protover=3&client=caniadd&clientver="
|
||||
PROG_VERSION "&enc=UTF-8", uname, pass), sizeof(buffer));
|
||||
enum error err = NOERR;
|
||||
|
||||
if (res_len == -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user