diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-08 23:20:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-08 23:20:42 +0000 |
commit | a983a0267109b1b6a8e16e476e2f2956a8771b94 (patch) | |
tree | 79bcae73cdb7b87b4f55d4396e79baea76ef53a6 /src/hello/address.c | |
parent | a3f8ef5b89dc44fc3acfb8f081a502f3409e4224 (diff) | |
download | gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.tar.gz gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.zip |
refactoring how we handle peer addresses in peerinfo/ats/transport/hello subsystems -- use a struct instead of 3--4 arguments
Diffstat (limited to 'src/hello/address.c')
-rw-r--r-- | src/hello/address.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/hello/address.c b/src/hello/address.c index 51fb296c3..5cfa10185 100644 --- a/src/hello/address.c +++ b/src/hello/address.c | |||
@@ -61,4 +61,49 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | |||
61 | return addr; | 61 | return addr; |
62 | } | 62 | } |
63 | 63 | ||
64 | |||
65 | /** | ||
66 | * Copy an address struct. | ||
67 | * | ||
68 | * @param address address to copy | ||
69 | * @return a copy of the address struct | ||
70 | */ | ||
71 | struct GNUNET_HELLO_Address * | ||
72 | GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) | ||
73 | { | ||
74 | return GNUNET_HELLO_address_allocate (&address->peer, | ||
75 | address->transport_name, | ||
76 | address->address, | ||
77 | address->address_length); | ||
78 | } | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Compare two addresses. Does NOT compare the peer identity, | ||
83 | * that is assumed already to match! | ||
84 | * | ||
85 | * @param a1 first address | ||
86 | * @param a2 second address | ||
87 | * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2. | ||
88 | */ | ||
89 | int | ||
90 | GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, | ||
91 | const struct GNUNET_HELLO_Address *a2) | ||
92 | { | ||
93 | int ret; | ||
94 | |||
95 | ret = strcmp (a1->transport_name, | ||
96 | a2->transport_name); | ||
97 | if (0 != ret) | ||
98 | return ret; | ||
99 | if (a1->address_length < a2->address_length) | ||
100 | return -1; | ||
101 | if (a1->address_length > a2->address_length) | ||
102 | return 1; | ||
103 | return memcmp (a1->address, | ||
104 | a1->address, | ||
105 | a1->address_length); | ||
106 | } | ||
107 | |||
108 | |||
64 | /* end of address.c */ | 109 | /* end of address.c */ |