1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 
20 #ifndef BSOCK_MEETING_H
21 #define BSOCK_MEETING_H
22 
23 /*
24  * Written by Eric Bollengier MMXVIII
25  */
26 
27 /*
28  * The BsockMeeting class is reponsible to create a meeting
29  * point between a client and a server.
30  *
31  * It can be used for example for Client that are behind a
32  * firewall and cannot be contacted by the Director.
33  *
34  * The Client can initiate the connection, it will be stored inside a
35  * BsockMeeting object. The Director can query the BsockMeeting object at any
36  * time and will wait to get the BSOCK object, or get the current one if any.
37  *
38  * The TCP keepalive settings are modified to maintain the connection alive and
39  * detect problems. The TCP settings are restored automatically.
40  */
41 class BsockMeeting: public SMARTALLOC
42 {
43 private:
44    BSOCK *socket;               /* Socket stored, NULL if empty */
45    int keepidle;                /* original keepidle setting */
46    int keepintvl;               /* original keepintvl setting */
47 
48    /* Initialized in the construction body */
49    pthread_mutex_t mutex;
50    pthread_cond_t  cond;
51 
52 public:
53    BsockMeeting();
54    ~BsockMeeting();
55 
56    void set(BSOCK *s);         /* Assign a BSOCK object */
57    bool is_set(POOLMEM *&host);/* Query if we have a BSOCK, and from who */
58    BSOCK *get(int timeout);   /* Get the current BSOCK Object, wait if needed */
59    void wait_request(BSOCK *dir); /* Wait for a Director request (client side) */
60 };
61 
62 #endif
63