sholsapp / gallocy

A distributed shared memory infrastructure.
27 stars 9 forks source link

Add a peer abstraction. #29

Closed sholsapp closed 8 years ago

sholsapp commented 8 years ago

We have various peer abstractions floating around the code base. Some uses are:

Both are used to identify the peer, but have different means of doing so. The consensus module makes use of the IP address as an integer. The http module makes use a struct sockaddr_in or IP address in string or integer form. The http module also needs a port, which is currently hard coded into the http module.

I think a peer needs things like the following:

Additionally, implementing this abstraction would create a better home for various utils functions that convert IP addresses between the various forms we use.

sholsapp commented 8 years ago

A few more changes are needed to refactor the code:

rverdon commented 8 years ago

I am looking at using the peer abstraction in the transport layer. To do that I am going to need a way to get at the IP and port. Perhaps it would be a good idea to add a _get_sockaddrin function.

It would just look something like:

struct sockaddr_in ip_addr;
memset(std::addressof(ip_addr), 0, sizeof(ip_addr));
ip_addr.sin_family = AF_INET;
ip_addr.sin_port = htons(port_integer);
uint32_t ipv4_addr = internet_address_integer & 0xFFFFFFFF;
ip_addr.sin_addr.s_addr = htonl(ipv4_addr);
return ip_addr;