[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] evhttp client/server example with https, IPv6, etc (was: evhttp client error handling)



Azat Khuzhin wrote:

It looks like that you don't have ipv6 support, maybe kernel module
don't loaded.
Try to test like this
$ ls /proc/net/if_inet6

No, I definitely have IPv6 support. That is how this came up in the first place: "localhost" on my machine resolves to both "::1" and "127.0.0.1", and libevent tries "::1" first.

What I don't have is a public IPv6 address. But that shouldn't prevent IPv6 from working on the loopback interface, or with link-local addresses on the other interfaces.

Here is what is on my machine:

ppelletier@chives:~$ uname -a
Linux chives 2.6.32-34-generic #77-Ubuntu SMP Tue Sep 13 19:39:17 UTC 2011 x86_64 GNU/Linux
ppelletier@chives:~$ ls /proc/net/if_inet6
/proc/net/if_inet6
ppelletier@chives:~$ cat /proc/net/if_inet6
fe80000000000000025056fffec00008 04 40 20 80   vmnet8
00000000000000000000000000000001 01 80 10 80       lo
fe80000000000000be305bfffeba2435 02 40 20 80     eth0
fe80000000000000025056fffec00001 03 40 20 80   vmnet1
ppelletier@chives:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr bc:30:5b:ba:24:35
          inet addr:10.10.130.228  Bcast:10.10.255.255  Mask:255.255.0.0
          inet6 addr: fe80::be30:5bff:feba:2435/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:537594652 errors:0 dropped:2315362 overruns:0 frame:765455
          TX packets:77470702 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:73560005284 (73.5 GB)  TX bytes:7637340989 (7.6 GB)
          Interrupt:17

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:256626215 errors:0 dropped:0 overruns:0 frame:0
          TX packets:256626215 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
RX bytes:194289637577 (194.2 GB) TX bytes:194289637577 (194.2 GB)

vmnet1    Link encap:Ethernet  HWaddr 00:50:56:c0:00:01
          inet addr:192.168.81.1  Bcast:192.168.81.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:49353 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7856 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

vmnet8    Link encap:Ethernet  HWaddr 00:50:56:c0:00:08
          inet addr:172.16.116.1  Bcast:172.16.116.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fec0:8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:47761 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4293 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ppelletier@chives:~$

What about IPv6 and IPv4 at the same time
There is socket option: IPV6_V6ONLY (ipv6 (7)), default value is 1.

But you can't set this option right using libevent, but you can set
default value for this option using using proc:
$ echo 0 | sudo tee -a /proc/sys/net/ipv6/bindv6only

The fact that this can't be set in libevent seems like a flaw. Asking the user to set the default value for the whole machine isn't an acceptable solution, because my goal here isn't to get the program working on my machine (there are any number of ways to do that), my goal is to have a program which can be deployed out into the world and work robustly on anybody's machine, regardless of exactly how their machine is configured.

If I just cared about getting it working for me right here, right now, I would just use IPv4 only. (And indeed that's what I'm doing right now; this whole thread is just an inquiry into what should I really be doing instead, if I wanted to do it right.) I want to be a good citizen and write a program that works equally well with IPv4 or IPv6. But, doing that seems to be quite tricky.

What I'd like is an example program that shows the "best practices" for how to use evhttp, as both a client and server, with https, and with all of the tricky things like error handling and IPv4/IPv6 support that are normally left out of examples. So what I'm thinking is that my https-example repo can serve as the basis for such an example, and once we get all these issues worked out, perhaps we can eventually contribute it back to the libevent repo, so that people in the future will have an easier time of doing this properly, without having to do as much experimentation as I have. (Currently, libevent only comes with an example for doing an http server. There is no http client example at all, and the server example doesn't cover https or IPv6.)

Thanks,

--Patrick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.