chiark / gitweb /
2345bf8f3684ebc2a66ddf4cf1be36a567279450
[elogind.git] / src / timesync / timesyncd-manager.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2014 Kay Sievers, Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "sd-event.h"
25 #include "sd-resolve.h"
26 #include "sd-network.h"
27 #include "list.h"
28 #include "socket-util.h"
29 #include "ratelimit.h"
30
31 typedef struct Manager Manager;
32
33 #include "timesyncd-server.h"
34
35 struct Manager {
36         sd_event *event;
37         sd_resolve *resolve;
38
39         LIST_HEAD(ServerName, system_servers);
40         LIST_HEAD(ServerName, link_servers);
41         LIST_HEAD(ServerName, fallback_servers);
42
43         RateLimit ratelimit;
44
45         /* network */
46         sd_event_source *network_event_source;
47         sd_network_monitor *network_monitor;
48
49         /* peer */
50         sd_resolve_query *resolve_query;
51         sd_event_source *event_receive;
52         ServerName *current_server_name;
53         ServerAddress *current_server_address;
54         int server_socket;
55         uint64_t packet_count;
56         sd_event_source *event_timeout;
57
58         /* last sent packet */
59         struct timespec trans_time_mon;
60         struct timespec trans_time;
61         usec_t retry_interval;
62         bool pending;
63
64         /* poll timer */
65         sd_event_source *event_timer;
66         usec_t poll_interval_usec;
67         bool poll_resync;
68
69         /* history data */
70         struct {
71                 double offset;
72                 double delay;
73         } samples[8];
74         unsigned int samples_idx;
75         double samples_jitter;
76
77         /* last change */
78         bool jumped;
79         bool sync;
80         int drift_ppm;
81
82         /* watch for time changes */
83         sd_event_source *event_clock_watch;
84         int clock_watch_fd;
85
86         /* Retry connections */
87         sd_event_source *event_retry;
88
89         /* RTC runs in local time, leave it alone */
90         bool rtc_local_time;
91 };
92
93 int manager_new(Manager **ret);
94 void manager_free(Manager *m);
95
96 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
97
98 void manager_set_server_name(Manager *m, ServerName *n);
99 void manager_set_server_address(Manager *m, ServerAddress *a);
100 void manager_flush_server_names(Manager *m, ServerType t);
101
102 int manager_connect(Manager *m);
103 void manager_disconnect(Manager *m);