-
Notifications
You must be signed in to change notification settings - Fork 298
tools: Rename IPC functions to reduce misleading #5
Conversation
|
85812c5
to
b869979
Compare
93fe674
to
20a230b
Compare
b869979
to
3cc6c6e
Compare
Improve the coding style of IPC APIs for WireGuard tools. This commit follows a previous PR at WireGuard#5 Signed-off-by: 刘群 <[email protected]>
The function name like ipc_get_device() is a little bit misleading. To make the code more readable for new developers, here are some suggestions: * Rename ipc_get_device(&dev) to ipc_fetch_conf(&conf) because it only fetches the runtime configuations from kernel. * Funtion prototype ipc_set_device(struct wgdevice *dev) is changed to ipc_set_device(const struct wgdevice *newconf). Change the following IPC function names and parameters which used to be confusing: ipc_set_device(dev) => ipc_set_device(newconf) ipc_get_device(dev, interface) => ipc_fetch_conf(conf, interface) kernel_set_device(dev) => kernel_set_device(newconf) kernel_get_device(device, interface) => kernel_fetch_conf(conf, interface) userspace_set_device(dev) => userspace_set_device(newconf) userspace_get_device(out, interface) => userspace_fetch_conf(out, interface) Renamed local variable/parameter symbols: * In showconf_main(), show_main(): device => conf * In ipc_fetch_conf(), kernel_fetch_conf(), userspace_fetch_conf(): dev => conf * In ipc_set_device(), kernel_set_device(), userspace_set_device(): dev => newconf Note: A lot of braces are added to the if-else code blocks to keep ourselves from making unexpected mistakes in the future. Changed function prototypes: int ipc_set_device(struct wgdevice *) => int ipc_set_device(const struct wgdevice *newconf) int kernel_set_device(struct wgdevice *) => int kernel_set_device(const struct wgdevice *newconf) int userspace_set_device(struct wgdevice *) => int userspace_set_device(const struct wgdevice *newconf) Signed-off-by: Liu Qun <[email protected]>
7f22bcc
to
2ad1122
Compare
Improve the coding style of IPC APIs for WireGuard tools. Signed-off-by: Liu Qun <[email protected]>
2ad1122
to
c9059b8
Compare
While I like the ideas in this, they are a bit intrusive and change the coding style in a way. And do it in one single big patch. |
4ffbc29
to
033dc89
Compare
I've found the on-line document In the document:
If we look into WireGuard/src/tools, we might found many if-else blocks didn‘t follow the last rule above, for example: |
Hi dear developers of WireGuard!
Recently, I've been reading the source code of WireGuard. The function name like ipc_get_device() looks to be a little bit misleading. To make the code more readable for new developers, here are some suggestions:
ipc_get_device(&dev)
toipc_fetch_conf(&conf)
because it only fetches the runtime configuations rather than a device instance or device handler.Change the following IPC function names and parameters which used to be confusing:
Renamed local variable/parameter symbols:
device => conf
dev => conf
dev => newconf
Note:
A lot of braces are added to the if-else code blocks to keep ourselves from making unexpected mistakes in the future.
Changed function prototypes:
int ipc_set_device(struct wgdevice *)
=>int ipc_set_device(const struct wgdevice *newconf)
int kernel_set_device(struct wgdevice *)
=>int kernel_set_device(const struct wgdevice *newconf)
int userspace_set_device(struct wgdevice *)
=>int userspace_set_device(const struct wgdevice *newconf)