diff options
author | t3sserakt <t3ss@posteo.de> | 2021-08-01 14:59:49 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-08-01 15:00:19 +0200 |
commit | af249ea5cef757a1e2b34cd2754febdb24a34416 (patch) | |
tree | b3ec473fbbeab70723fb7339992c8026004d00c0 | |
parent | 61375320041b2c11ef9c10c21239fd2e24692a9a (diff) | |
parent | c98bf47a8fc54e1dc9e413c0cb4506789a9ddeee (diff) | |
download | gnunet-af249ea5cef757a1e2b34cd2754febdb24a34416.tar.gz gnunet-af249ea5cef757a1e2b34cd2754febdb24a34416.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
-rw-r--r-- | debian/changelog | 8 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debian/gnunet.postinst | 178 | ||||
-rw-r--r-- | src/include/gnunet_db_lib.h | 43 | ||||
-rw-r--r-- | src/include/gnunet_pq_lib.h | 67 | ||||
-rw-r--r-- | src/pq/pq_event.c | 68 |
6 files changed, 153 insertions, 213 deletions
diff --git a/debian/changelog b/debian/changelog index f27aba2af..b78688984 100644 --- a/debian/changelog +++ b/debian/changelog | |||
@@ -1,3 +1,11 @@ | |||
1 | gnunet (0.14.1-12) unstable; urgency=low | ||
2 | |||
3 | * Lower debhelper compatibility level to 12. | ||
4 | * Do not inject user units in postinst for now. | ||
5 | * Tweaks to packaging. | ||
6 | |||
7 | -- Florian Dold <florian@dold.me> Sat, 31 Jul 2021 20:04:42 +0200 | ||
8 | |||
1 | gnunet (0.14.1-11) unstable; urgency=low | 9 | gnunet (0.14.1-11) unstable; urgency=low |
2 | 10 | ||
3 | * Make configuration parsing more permissive. | 11 | * Make configuration parsing more permissive. |
diff --git a/debian/control b/debian/control index 01b549286..57acc6e1e 100644 --- a/debian/control +++ b/debian/control | |||
@@ -6,7 +6,7 @@ Build-Depends: | |||
6 | autoconf (>=2.59), | 6 | autoconf (>=2.59), |
7 | automake (>=1.11.1), | 7 | automake (>=1.11.1), |
8 | autopoint, | 8 | autopoint, |
9 | debhelper-compat (= 13), | 9 | debhelper-compat (= 12), |
10 | gettext, | 10 | gettext, |
11 | iptables, | 11 | iptables, |
12 | libbluetooth-dev, | 12 | libbluetooth-dev, |
diff --git a/debian/gnunet.postinst b/debian/gnunet.postinst index b6317f5be..091feb223 100644 --- a/debian/gnunet.postinst +++ b/debian/gnunet.postinst | |||
@@ -108,114 +108,63 @@ case "${1}" in | |||
108 | echo " done." | 108 | echo " done." |
109 | fi | 109 | fi |
110 | 110 | ||
111 | # Install GNUnet configuration for all users provided non exists | 111 | # # Change the proxy settings for Firefox and Chromium if desired |
112 | userlist=$(awk -F ':' '$3>=1000 && $3<2000 {print $1}' /etc/passwd) | 112 | # if ${_PROXY} |
113 | users=($userlist) | 113 | # then |
114 | homedirlist=$(awk -F ':' '$3>=1000 && $3<2000 {print $6}' /etc/passwd) | 114 | # mkdir -p /etc/X11/xinit/xinitrc.d/ |
115 | homedirs=($homedirlist) | 115 | #cat > "/etc/X11/xinit/xinitrc.d/80-gnunet-user-services" << "EOF" |
116 | 116 | ##!/bin/bash | |
117 | for (( i=0; i<${#users[@]}; i++ )); do | 117 | #systemctl --user daemon-reload |
118 | usermod -aG gnunet ${users[$i]} | 118 | #systemctl --user start gnunet-user |
119 | if [ -n "$i" ] && [ -d "${homedirs[$i]}" ]; then | 119 | #systemctl --user enable gnunet-user |
120 | mkdir -p ${homedirs[$i]}/.config/systemd/user/ | 120 | #user=$(whoami) |
121 | 121 | #gnunet_proxy=$(gnunet-config -c /etc/skel/.config/gnunet.conf -s gns-proxy | grep 'IMMEDIATE_START = YES') | |
122 | cat > "${homedirs[$i]}/.config/systemd/user/gnunet-user.service" << EOF | ||
123 | # Copyright (C) 2019 GNUnet e.V. | ||
124 | # | 122 | # |
125 | # Copying and distribution of this file, with or without modification, | 123 | ## Enable GNS proxy for new users informed by /etc/skel. |
126 | # are permitted in any medium without royalty provided the copyright | 124 | #if [ "$gnunet_proxy" ]; then |
127 | # notice and this notice are preserved. This file is offered as-is, | 125 | # |
128 | # without any warranty. | 126 | # # Calculate user specific port |
129 | 127 | # port=$((8000+$(id -u $user))) | |
130 | [Unit] | 128 | # |
131 | Description=Service that runs a GNUnet for the user gnunet | 129 | # gnunet-config -c $HOME/.config/gnunet.conf \ |
132 | After=network.target | 130 | # --section=gns-proxy \ |
133 | 131 | # --option=OPTIONS \ | |
134 | [Service] | 132 | # --value="-p $port" |
135 | Type=forking | 133 | # |
136 | ExecStart=/usr/bin/gnunet-arm -s -c ${homedirs[$i]}/.config/gnunet.conf | 134 | # # Firefox |
137 | ExecStop=/usr/bin/gnunet-arm -e -c ${homedirs[$i]}/.config/gnunet.conf | 135 | # defaultprofile=$(ls $HOME/.mozilla/firefox/*.default) |
138 | 136 | # if [ ! "$defaultprofile" ];then | |
139 | [Install] | 137 | # timeout 3s firefox --headless # dirty: create profile if not existent |
140 | WantedBy=multi-user.target | 138 | # fi |
141 | EOF | 139 | # for ffprofile in $HOME/.mozilla/firefox/*.*/; do |
142 | 140 | # js=$ffprofile/user.js | |
143 | chown "${users[$i]}":"${users[$i]}" "${homedirs[$i]}/.config/systemd/user/gnunet-user.service" | 141 | # if [ -f "$js" ]; then |
144 | if [ ! -f "${homedirs[$i]}/.config/gnunet.conf" ]; then | 142 | # sed -i '/Preferences for using the GNU Name System/d' "$js" |
145 | mkdir -p ${homedirs[$i]}/.config/ | 143 | # sed -i '/network.proxy.socks/d' "$js" |
146 | cp /etc/skel/.config/gnunet.conf "${homedirs[$i]}/.config/gnunet.conf" | 144 | # sed -i '/network.proxy.socks_port/d' "$js" |
147 | chmod 644 "${homedirs[$i]}/.config/gnunet.conf" | 145 | # sed -i '/network.proxy.socks_remote_dns/d' "$js" |
148 | fi | 146 | # sed -i '/network.proxy.type/d' "$js" |
149 | fi | 147 | # fi |
150 | port=$((8000+$(id -u "${users[$i]}"))) | 148 | # echo "// Preferences for using the GNU Name System" >> "$js" |
151 | gnunet-config -c "${homedirs[$i]}/.config/gnunet.conf" \ | 149 | # echo "user_pref(\"network.proxy.socks\", \"localhost\");" >> "$js" |
152 | --section=gns-proxy \ | 150 | # echo "user_pref(\"network.proxy.socks_port\", $port);" >> "$js" |
153 | --option=IMMEDIATE_START \ | 151 | # echo "user_pref(\"network.proxy.socks_remote_dns\", true);" >> "$js" |
154 | --value=YES | 152 | # echo "user_pref(\"network.proxy.type\", 1);" >> "$js" |
155 | gnunet-config -c "${homedirs[$i]}/.config/gnunet.conf" \ | 153 | # done |
156 | --section=gns-proxy \ | 154 | # |
157 | --option=OPTIONS \ | 155 | # # Chromium |
158 | --value="-p $port" | 156 | # profile="$HOME/.profile" |
159 | chown "${users[$i]}":"${users[$i]}" "${homedirs[$i]}/.config/gnunet.conf" | 157 | # if [ -f "$profile" ]; then |
160 | done | 158 | # sed -i '/CHROMIUM_USER_FLAGS/d' "$profile" |
161 | 159 | # fi | |
162 | # Change the proxy settings for Firefox and Chromium if desired | 160 | # echo "export CHROMIUM_USER_FLAGS=--proxy-server=socks5://localhost:$port" \ |
163 | if ${_PROXY} | 161 | # >> "$profile" |
164 | then | 162 | #fi |
165 | mkdir -p /etc/X11/xinit/xinitrc.d/ | 163 | # |
166 | cat > "/etc/X11/xinit/xinitrc.d/80-gnunet-user-services" << "EOF" | 164 | ## Create/Renew GNS certificate authority (CA) per user. |
167 | #!/bin/bash | 165 | #gnunet-gns-proxy-setup-ca |
168 | systemctl --user daemon-reload | 166 | #EOF |
169 | systemctl --user start gnunet-user | 167 | # fi |
170 | systemctl --user enable gnunet-user | ||
171 | user=$(whoami) | ||
172 | gnunet_proxy=$(gnunet-config -c /etc/skel/.config/gnunet.conf -s gns-proxy | grep 'IMMEDIATE_START = YES') | ||
173 | |||
174 | # Enable GNS proxy for new users informed by /etc/skel. | ||
175 | if [ "$gnunet_proxy" ]; then | ||
176 | |||
177 | # Calculate user specific port | ||
178 | port=$((8000+$(id -u $user))) | ||
179 | |||
180 | gnunet-config -c $HOME/.config/gnunet.conf \ | ||
181 | --section=gns-proxy \ | ||
182 | --option=OPTIONS \ | ||
183 | --value="-p $port" | ||
184 | |||
185 | # Firefox | ||
186 | defaultprofile=$(ls $HOME/.mozilla/firefox/*.default) | ||
187 | if [ ! "$defaultprofile" ];then | ||
188 | timeout 3s firefox --headless # dirty: create profile if not existent | ||
189 | fi | ||
190 | for ffprofile in $HOME/.mozilla/firefox/*.*/; do | ||
191 | js=$ffprofile/user.js | ||
192 | if [ -f "$js" ]; then | ||
193 | sed -i '/Preferences for using the GNU Name System/d' "$js" | ||
194 | sed -i '/network.proxy.socks/d' "$js" | ||
195 | sed -i '/network.proxy.socks_port/d' "$js" | ||
196 | sed -i '/network.proxy.socks_remote_dns/d' "$js" | ||
197 | sed -i '/network.proxy.type/d' "$js" | ||
198 | fi | ||
199 | echo "// Preferences for using the GNU Name System" >> "$js" | ||
200 | echo "user_pref(\"network.proxy.socks\", \"localhost\");" >> "$js" | ||
201 | echo "user_pref(\"network.proxy.socks_port\", $port);" >> "$js" | ||
202 | echo "user_pref(\"network.proxy.socks_remote_dns\", true);" >> "$js" | ||
203 | echo "user_pref(\"network.proxy.type\", 1);" >> "$js" | ||
204 | done | ||
205 | |||
206 | # Chromium | ||
207 | profile="$HOME/.profile" | ||
208 | if [ -f "$profile" ]; then | ||
209 | sed -i '/CHROMIUM_USER_FLAGS/d' "$profile" | ||
210 | fi | ||
211 | echo "export CHROMIUM_USER_FLAGS=--proxy-server=socks5://localhost:$port" \ | ||
212 | >> "$profile" | ||
213 | fi | ||
214 | |||
215 | # Create/Renew GNS certificate authority (CA) per user. | ||
216 | gnunet-gns-proxy-setup-ca | ||
217 | EOF | ||
218 | fi | ||
219 | 168 | ||
220 | # Update files and directories permissions. | 169 | # Update files and directories permissions. |
221 | # Assuming default values, this *should* not be changed. | 170 | # Assuming default values, this *should* not be changed. |
@@ -267,21 +216,6 @@ GNUNET_GROUP=${_GROUPNAME} | |||
267 | GNUNET_AUTOSTART="${_AUTOSTART}" | 216 | GNUNET_AUTOSTART="${_AUTOSTART}" |
268 | EOF | 217 | EOF |
269 | 218 | ||
270 | cat > "/etc/systemd/system/gnunet.service" <<EOF | ||
271 | [Unit] | ||
272 | Description=A framework for secure peer-to-peer networking | ||
273 | |||
274 | [Service] | ||
275 | EnvironmentFile=/etc/default/gnunet | ||
276 | User=${_USERNAME} | ||
277 | Type=forking | ||
278 | ExecStart=/usr/bin/gnunet-arm -s -c /etc/gnunet.conf | ||
279 | ExecStop=/usr/bin/gnunet-arm -e -c /etc/gnunet.conf | ||
280 | |||
281 | [Install] | ||
282 | WantedBy=multi-user.target | ||
283 | EOF | ||
284 | |||
285 | cp -f "${CONFIG_NEW}" "${CONFIG_FILE}" | 219 | cp -f "${CONFIG_NEW}" "${CONFIG_FILE}" |
286 | echo " done." | 220 | echo " done." |
287 | 221 | ||
diff --git a/src/include/gnunet_db_lib.h b/src/include/gnunet_db_lib.h index 85ad13e31..63c45112d 100644 --- a/src/include/gnunet_db_lib.h +++ b/src/include/gnunet_db_lib.h | |||
@@ -61,4 +61,47 @@ enum GNUNET_DB_QueryStatus | |||
61 | that returned more than one result. */ | 61 | that returned more than one result. */ |
62 | }; | 62 | }; |
63 | 63 | ||
64 | |||
65 | /** | ||
66 | * Handle for an active LISTENer to a database. | ||
67 | */ | ||
68 | struct GNUNET_DB_EventHandler; | ||
69 | |||
70 | /** | ||
71 | * Function called on events received from Postgres. | ||
72 | * | ||
73 | * @param cls closure | ||
74 | * @param extra additional event data provided | ||
75 | * @param extra_size number of bytes in @a extra | ||
76 | */ | ||
77 | typedef void | ||
78 | (*GNUNET_DB_EventCallback)(void *cls, | ||
79 | const void *extra, | ||
80 | size_t extra_size); | ||
81 | |||
82 | GNUNET_NETWORK_STRUCT_BEGIN | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Header of a structure that describes an | ||
87 | * event channel we may subscribe to or notify on. | ||
88 | */ | ||
89 | struct GNUNET_DB_EventHeaderP | ||
90 | { | ||
91 | /** | ||
92 | * The length of the struct (in bytes, including the length field itself), | ||
93 | * in big-endian format. | ||
94 | */ | ||
95 | uint16_t size GNUNET_PACKED; | ||
96 | |||
97 | /** | ||
98 | * The type of the message (GNUNET_DB_EVENT_TYPE_XXXX), in big-endian format. | ||
99 | */ | ||
100 | uint16_t type GNUNET_PACKED; | ||
101 | |||
102 | }; | ||
103 | |||
104 | GNUNET_NETWORK_STRUCT_END | ||
105 | |||
106 | |||
64 | #endif | 107 | #endif |
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index 1f2915165..ecc2b9719 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h | |||
@@ -853,7 +853,7 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db); | |||
853 | 853 | ||
854 | 854 | ||
855 | /** | 855 | /** |
856 | * Function called whenever the socket needed for | 856 | * Function called whenever the socket needed for |
857 | * notifications from postgres changes. | 857 | * notifications from postgres changes. |
858 | * | 858 | * |
859 | * @param cls closure | 859 | * @param cls closure |
@@ -868,7 +868,7 @@ typedef void | |||
868 | * Obtain the file descriptor to poll on for notifications. | 868 | * Obtain the file descriptor to poll on for notifications. |
869 | * Useful if the GNUnet scheduler is NOT to be used for | 869 | * Useful if the GNUnet scheduler is NOT to be used for |
870 | * such notifications. | 870 | * such notifications. |
871 | * | 871 | * |
872 | * @param db database handle | 872 | * @param db database handle |
873 | * @param sc function to call with the socket | 873 | * @param sc function to call with the socket |
874 | * @param sc_cls closure for @a sc | 874 | * @param sc_cls closure for @a sc |
@@ -911,55 +911,8 @@ GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db); | |||
911 | 911 | ||
912 | 912 | ||
913 | /** | 913 | /** |
914 | * Handle for an active LISTENer to the database. | ||
915 | */ | ||
916 | struct GNUNET_PQ_EventHandler; | ||
917 | |||
918 | /** | ||
919 | * Function called on events received from Postgres. | ||
920 | * | ||
921 | * @param cls closure | ||
922 | * @param extra additional event data provided | ||
923 | * @param extra_size number of bytes in @a extra | ||
924 | */ | ||
925 | typedef void | ||
926 | (*GNUNET_PQ_EventCallback)(void *cls, | ||
927 | const void *extra, | ||
928 | size_t extra_size); | ||
929 | |||
930 | GNUNET_NETWORK_STRUCT_BEGIN | ||
931 | |||
932 | |||
933 | /** | ||
934 | * Header of a structure that describes an | ||
935 | * event channel we may subscribe to or notify on. | ||
936 | */ | ||
937 | struct GNUNET_PQ_EventHeaderP | ||
938 | { | ||
939 | /** | ||
940 | * The length of the struct (in bytes, including the length field itself), | ||
941 | * in big-endian format. | ||
942 | */ | ||
943 | uint16_t size GNUNET_PACKED; | ||
944 | |||
945 | /** | ||
946 | * The type of the message (GNUNET_PQ_EVENT_TYPE_XXXX), in big-endian format. | ||
947 | */ | ||
948 | uint16_t type GNUNET_PACKED; | ||
949 | |||
950 | }; | ||
951 | |||
952 | GNUNET_NETWORK_STRUCT_END | ||
953 | |||
954 | |||
955 | /** | ||
956 | * Handle for an active LISTENer to the database. | ||
957 | */ | ||
958 | struct GNUNET_PQ_EventHandler; | ||
959 | |||
960 | /** | ||
961 | * Register callback to be invoked on events of type @a es. | 914 | * Register callback to be invoked on events of type @a es. |
962 | * | 915 | * |
963 | * Unlike many other calls, this function is thread-safe | 916 | * Unlike many other calls, this function is thread-safe |
964 | * and may be called from threads that are different | 917 | * and may be called from threads that are different |
965 | * from the one that setup @a db. However, the @a cb | 918 | * from the one that setup @a db. However, the @a cb |
@@ -973,16 +926,16 @@ struct GNUNET_PQ_EventHandler; | |||
973 | * @param cb_cls closure for @a cb | 926 | * @param cb_cls closure for @a cb |
974 | * @return handle useful to cancel the listener | 927 | * @return handle useful to cancel the listener |
975 | */ | 928 | */ |
976 | struct GNUNET_PQ_EventHandler * | 929 | struct GNUNET_DB_EventHandler * |
977 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | 930 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, |
978 | const struct GNUNET_PQ_EventHeaderP *es, | 931 | const struct GNUNET_DB_EventHeaderP *es, |
979 | GNUNET_PQ_EventCallback cb, | 932 | GNUNET_DB_EventCallback cb, |
980 | void *cb_cls); | 933 | void *cb_cls); |
981 | 934 | ||
982 | 935 | ||
983 | /** | 936 | /** |
984 | * Stop notifications. | 937 | * Stop notifications. |
985 | * | 938 | * |
986 | * Unlike many other calls, this function is thread-safe | 939 | * Unlike many other calls, this function is thread-safe |
987 | * and may be called from threads that are different | 940 | * and may be called from threads that are different |
988 | * from the one that setup @a db. However, the @a cb | 941 | * from the one that setup @a db. However, the @a cb |
@@ -992,12 +945,12 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
992 | * @param eh handle to unregister. | 945 | * @param eh handle to unregister. |
993 | */ | 946 | */ |
994 | void | 947 | void |
995 | GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh); | 948 | GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh); |
996 | 949 | ||
997 | 950 | ||
998 | /** | 951 | /** |
999 | * Notify all that listen on @a es of an event. | 952 | * Notify all that listen on @a es of an event. |
1000 | * | 953 | * |
1001 | * Unlike many other calls, this function is thread-safe | 954 | * Unlike many other calls, this function is thread-safe |
1002 | * and may be called from threads that are different | 955 | * and may be called from threads that are different |
1003 | * from the one that setup @a db. However, the @a cb | 956 | * from the one that setup @a db. However, the @a cb |
@@ -1011,7 +964,7 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh); | |||
1011 | */ | 964 | */ |
1012 | void | 965 | void |
1013 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, | 966 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, |
1014 | const struct GNUNET_PQ_EventHeaderP *es, | 967 | const struct GNUNET_DB_EventHeaderP *es, |
1015 | const void *extra, | 968 | const void *extra, |
1016 | size_t extra_size); | 969 | size_t extra_size); |
1017 | 970 | ||
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c index 74b8b3653..bf845db18 100644 --- a/src/pq/pq_event.c +++ b/src/pq/pq_event.c | |||
@@ -29,8 +29,8 @@ | |||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Handle for an active LISTENer to the database. | 31 | * Handle for an active LISTENer to the database. |
32 | */ | 32 | */ |
33 | struct GNUNET_PQ_EventHandler | 33 | struct GNUNET_DB_EventHandler |
34 | { | 34 | { |
35 | /** | 35 | /** |
36 | * Channel name. | 36 | * Channel name. |
@@ -40,7 +40,7 @@ struct GNUNET_PQ_EventHandler | |||
40 | /** | 40 | /** |
41 | * Function to call on events. | 41 | * Function to call on events. |
42 | */ | 42 | */ |
43 | GNUNET_PQ_EventCallback cb; | 43 | GNUNET_DB_EventCallback cb; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Closure for @e cb. | 46 | * Closure for @e cb. |
@@ -54,8 +54,6 @@ struct GNUNET_PQ_EventHandler | |||
54 | }; | 54 | }; |
55 | 55 | ||
56 | 56 | ||
57 | |||
58 | |||
59 | /** | 57 | /** |
60 | * Convert @a es to a short hash. | 58 | * Convert @a es to a short hash. |
61 | * | 59 | * |
@@ -63,7 +61,7 @@ struct GNUNET_PQ_EventHandler | |||
63 | * @param[out] sh short hash to set | 61 | * @param[out] sh short hash to set |
64 | */ | 62 | */ |
65 | static void | 63 | static void |
66 | es_to_sh (const struct GNUNET_PQ_EventHeaderP *es, | 64 | es_to_sh (const struct GNUNET_DB_EventHeaderP *es, |
67 | struct GNUNET_ShortHashCode *sh) | 65 | struct GNUNET_ShortHashCode *sh) |
68 | { | 66 | { |
69 | struct GNUNET_HashCode h_channel; | 67 | struct GNUNET_HashCode h_channel; |
@@ -111,7 +109,7 @@ sh_to_channel (struct GNUNET_ShortHashCode *sh, | |||
111 | * @return end position of the identifier | 109 | * @return end position of the identifier |
112 | */ | 110 | */ |
113 | static char * | 111 | static char * |
114 | es_to_channel (const struct GNUNET_PQ_EventHeaderP *es, | 112 | es_to_channel (const struct GNUNET_DB_EventHeaderP *es, |
115 | char identifier[64]) | 113 | char identifier[64]) |
116 | { | 114 | { |
117 | struct GNUNET_ShortHashCode sh; | 115 | struct GNUNET_ShortHashCode sh; |
@@ -141,12 +139,12 @@ struct NotifyContext | |||
141 | 139 | ||
142 | 140 | ||
143 | /** | 141 | /** |
144 | * Function called on every event handler that | 142 | * Function called on every event handler that |
145 | * needs to be triggered. | 143 | * needs to be triggered. |
146 | * | 144 | * |
147 | * @param cls a `struct NotifyContext` | 145 | * @param cls a `struct NotifyContext` |
148 | * @param sh channel name | 146 | * @param sh channel name |
149 | * @param value a `struct GNUNET_PQ_EventHandler` | 147 | * @param value a `struct GNUNET_DB_EventHandler` |
150 | * @return #GNUNET_OK continue to iterate | 148 | * @return #GNUNET_OK continue to iterate |
151 | */ | 149 | */ |
152 | static int | 150 | static int |
@@ -155,13 +153,13 @@ do_notify (void *cls, | |||
155 | void *value) | 153 | void *value) |
156 | { | 154 | { |
157 | struct NotifyContext *ctx = cls; | 155 | struct NotifyContext *ctx = cls; |
158 | struct GNUNET_PQ_EventHandler *eh = value; | 156 | struct GNUNET_DB_EventHandler *eh = value; |
159 | 157 | ||
160 | eh->cb (eh->cb_cls, | 158 | eh->cb (eh->cb_cls, |
161 | ctx->extra, | 159 | ctx->extra, |
162 | ctx->extra_size); | 160 | ctx->extra_size); |
163 | return GNUNET_OK; | 161 | return GNUNET_OK; |
164 | } | 162 | } |
165 | 163 | ||
166 | 164 | ||
167 | void | 165 | void |
@@ -194,6 +192,7 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db) | |||
194 | 192 | ||
195 | GNUNET_assert (0 == | 193 | GNUNET_assert (0 == |
196 | pthread_mutex_lock (&db->notify_lock)); | 194 | pthread_mutex_lock (&db->notify_lock)); |
195 | PQconsumeInput (db->conn); | ||
197 | while (NULL != (n = PQnotifies (db->conn))) | 196 | while (NULL != (n = PQnotifies (db->conn))) |
198 | { | 197 | { |
199 | struct GNUNET_ShortHashCode sh; | 198 | struct GNUNET_ShortHashCode sh; |
@@ -210,6 +209,7 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db) | |||
210 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
211 | "Ignoring notification for unsupported channel identifier `%s'\n", | 210 | "Ignoring notification for unsupported channel identifier `%s'\n", |
212 | n->relname); | 211 | n->relname); |
212 | PQfreemem (n); | ||
213 | continue; | 213 | continue; |
214 | } | 214 | } |
215 | if ( (NULL != n->extra) && | 215 | if ( (NULL != n->extra) && |
@@ -223,12 +223,14 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db) | |||
223 | "Ignoring notification for unsupported extra data `%s' on channel `%s'\n", | 223 | "Ignoring notification for unsupported extra data `%s' on channel `%s'\n", |
224 | n->extra, | 224 | n->extra, |
225 | n->relname); | 225 | n->relname); |
226 | PQfreemem (n); | ||
226 | continue; | 227 | continue; |
227 | } | 228 | } |
228 | GNUNET_CONTAINER_multishortmap_iterate (db->channel_map, | 229 | GNUNET_CONTAINER_multishortmap_iterate (db->channel_map, |
229 | &do_notify, | 230 | &do_notify, |
230 | &ctx); | 231 | &ctx); |
231 | GNUNET_free (ctx.extra); | 232 | GNUNET_free (ctx.extra); |
233 | PQfreemem (n); | ||
232 | } | 234 | } |
233 | GNUNET_assert (0 == | 235 | GNUNET_assert (0 == |
234 | pthread_mutex_unlock (&db->notify_lock)); | 236 | pthread_mutex_unlock (&db->notify_lock)); |
@@ -265,7 +267,7 @@ do_scheduler_notify (void *cls) | |||
265 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, | 267 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, |
266 | db->rfd, | 268 | db->rfd, |
267 | &do_scheduler_notify, | 269 | &do_scheduler_notify, |
268 | db); | 270 | db); |
269 | } | 271 | } |
270 | 272 | ||
271 | 273 | ||
@@ -281,7 +283,7 @@ scheduler_fd_cb (void *cls, | |||
281 | int fd) | 283 | int fd) |
282 | { | 284 | { |
283 | struct GNUNET_PQ_Context *db = cls; | 285 | struct GNUNET_PQ_Context *db = cls; |
284 | 286 | ||
285 | if (NULL != db->event_task) | 287 | if (NULL != db->event_task) |
286 | { | 288 | { |
287 | GNUNET_SCHEDULER_cancel (db->event_task); | 289 | GNUNET_SCHEDULER_cancel (db->event_task); |
@@ -305,7 +307,7 @@ void | |||
305 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) | 307 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) |
306 | { | 308 | { |
307 | int fd; | 309 | int fd; |
308 | 310 | ||
309 | GNUNET_assert (! db->scheduler_on); | 311 | GNUNET_assert (! db->scheduler_on); |
310 | GNUNET_assert (NULL == db->sc); | 312 | GNUNET_assert (NULL == db->sc); |
311 | db->scheduler_on = true; | 313 | db->scheduler_on = true; |
@@ -335,7 +337,7 @@ GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db) | |||
335 | static void | 337 | static void |
336 | manage_subscribe (struct GNUNET_PQ_Context *db, | 338 | manage_subscribe (struct GNUNET_PQ_Context *db, |
337 | const char *cmd, | 339 | const char *cmd, |
338 | struct GNUNET_PQ_EventHandler *eh) | 340 | struct GNUNET_DB_EventHandler *eh) |
339 | { | 341 | { |
340 | char sql[16 + 64]; | 342 | char sql[16 + 64]; |
341 | char *end; | 343 | char *end; |
@@ -379,13 +381,13 @@ register_notify (void *cls, | |||
379 | void *value) | 381 | void *value) |
380 | { | 382 | { |
381 | struct GNUNET_PQ_Context *db = cls; | 383 | struct GNUNET_PQ_Context *db = cls; |
382 | struct GNUNET_PQ_EventHandler *eh = value; | 384 | struct GNUNET_DB_EventHandler *eh = value; |
383 | 385 | ||
384 | manage_subscribe (db, | 386 | manage_subscribe (db, |
385 | "LISTEN ", | 387 | "LISTEN ", |
386 | eh); | 388 | eh); |
387 | return GNUNET_OK; | 389 | return GNUNET_OK; |
388 | } | 390 | } |
389 | 391 | ||
390 | 392 | ||
391 | void | 393 | void |
@@ -401,16 +403,16 @@ GNUNET_PQ_event_reconnect_ (struct GNUNET_PQ_Context *db) | |||
401 | } | 403 | } |
402 | 404 | ||
403 | 405 | ||
404 | struct GNUNET_PQ_EventHandler * | 406 | struct GNUNET_DB_EventHandler * |
405 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | 407 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, |
406 | const struct GNUNET_PQ_EventHeaderP *es, | 408 | const struct GNUNET_DB_EventHeaderP *es, |
407 | GNUNET_PQ_EventCallback cb, | 409 | GNUNET_DB_EventCallback cb, |
408 | void *cb_cls) | 410 | void *cb_cls) |
409 | { | 411 | { |
410 | struct GNUNET_PQ_EventHandler *eh; | 412 | struct GNUNET_DB_EventHandler *eh; |
411 | bool was_zero; | 413 | bool was_zero; |
412 | 414 | ||
413 | eh = GNUNET_new (struct GNUNET_PQ_EventHandler); | 415 | eh = GNUNET_new (struct GNUNET_DB_EventHandler); |
414 | eh->db = db; | 416 | eh->db = db; |
415 | es_to_sh (es, | 417 | es_to_sh (es, |
416 | &eh->sh); | 418 | &eh->sh); |
@@ -421,14 +423,14 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
421 | was_zero = (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)); | 423 | was_zero = (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)); |
422 | GNUNET_assert (GNUNET_OK == | 424 | GNUNET_assert (GNUNET_OK == |
423 | GNUNET_CONTAINER_multishortmap_put (db->channel_map, | 425 | GNUNET_CONTAINER_multishortmap_put (db->channel_map, |
424 | &eh->sh, | 426 | &eh->sh, |
425 | eh, | 427 | eh, |
426 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 428 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
427 | if ( (NULL != db->sc) && | 429 | if ( (NULL != db->sc) && |
428 | was_zero) | 430 | was_zero) |
429 | { | 431 | { |
430 | int fd = PQsocket (db->conn); | 432 | int fd = PQsocket (db->conn); |
431 | 433 | ||
432 | if (-1 != fd) | 434 | if (-1 != fd) |
433 | db->sc (db->sc_cls, | 435 | db->sc (db->sc_cls, |
434 | fd); | 436 | fd); |
@@ -443,7 +445,7 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
443 | 445 | ||
444 | 446 | ||
445 | void | 447 | void |
446 | GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh) | 448 | GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) |
447 | { | 449 | { |
448 | struct GNUNET_PQ_Context *db = eh->db; | 450 | struct GNUNET_PQ_Context *db = eh->db; |
449 | 451 | ||
@@ -451,9 +453,9 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh) | |||
451 | pthread_mutex_lock (&db->notify_lock)); | 453 | pthread_mutex_lock (&db->notify_lock)); |
452 | GNUNET_assert (GNUNET_OK == | 454 | GNUNET_assert (GNUNET_OK == |
453 | GNUNET_CONTAINER_multishortmap_remove (db->channel_map, | 455 | GNUNET_CONTAINER_multishortmap_remove (db->channel_map, |
454 | &eh->sh, | 456 | &eh->sh, |
455 | eh)); | 457 | eh)); |
456 | 458 | ||
457 | manage_subscribe (db, | 459 | manage_subscribe (db, |
458 | "UNLISTEN ", | 460 | "UNLISTEN ", |
459 | eh); | 461 | eh); |
@@ -471,7 +473,7 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh) | |||
471 | 473 | ||
472 | void | 474 | void |
473 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, | 475 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, |
474 | const struct GNUNET_PQ_EventHeaderP *es, | 476 | const struct GNUNET_DB_EventHeaderP *es, |
475 | const void *extra, | 477 | const void *extra, |
476 | size_t extra_size) | 478 | size_t extra_size) |
477 | { | 479 | { |
@@ -512,5 +514,5 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, | |||
512 | PQclear (result); | 514 | PQclear (result); |
513 | } | 515 | } |
514 | 516 | ||
515 | /* end of pq_event.c */ | ||
516 | 517 | ||
518 | /* end of pq_event.c */ | ||