File: tmate-ssh-latency.c

package info (click to toggle)
tmate-ssh-server 2.3.0-68-gd7334ee4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,552 kB
  • sloc: ansic: 39,257; awk: 339; makefile: 251; sh: 129; ruby: 45; perl: 41
file content (45 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <sys/wait.h>
#include <stdio.h>
#include <event.h>
#include <arpa/inet.h>
#include <time.h>

#include "tmate.h"

static void on_keepalive_timer(evutil_socket_t fd, short what, void *arg);

void start_keepalive_timer(struct tmate_ssh_client *client, int timeout_ms)
{
	struct timeval tv;
	tv.tv_sec = timeout_ms / 1000;
	tv.tv_usec = (timeout_ms % 1000)*1000;

	client->keepalive_interval_ms = timeout_ms;

	evtimer_set(&client->ev_keepalive_timer, on_keepalive_timer, client);
	evtimer_add(&client->ev_keepalive_timer, &tv);
}

static void on_keepalive_timer(__unused evutil_socket_t fd,
			       __unused short what, void *arg)
{
	struct tmate_ssh_client *client = arg;

	/*
	 * libssh 0.8.4, 0.8.5, and 0.8.6 can't handle the response of the
	 * keepalives due to packet filtering.
	 */

	if (ssh_version(SSH_VERSION_INT(0,8,4)) && !ssh_version(SSH_VERSION_INT(0,8,7)))
		return;

	if (ssh_send_keepalive(client->session) == SSH_ERROR)
		return;

	start_keepalive_timer(client, client->keepalive_interval_ms);
}