Ensure all SPTPS functions are prefixed with sptps_.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 26 Feb 2012 11:33:16 +0000 (12:33 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 26 Feb 2012 11:33:16 +0000 (12:33 +0100)
src/connection.c
src/meta.c
src/protocol_auth.c
src/sptps.c
src/sptps.h
src/sptps_test.c

index b61609a..ee44e53 100644 (file)
@@ -69,7 +69,7 @@ void free_connection(connection_t *c) {
        cipher_close(&c->outcipher);
        digest_close(&c->outdigest);
 
-       stop_sptps(&c->sptps);
+       sptps_stop(&c->sptps);
        ecdsa_free(&c->ecdsa);
        rsa_free(&c->rsa);
 
index baa4c2e..fa031db 100644 (file)
@@ -57,7 +57,7 @@ bool send_meta(connection_t *c, const char *buffer, int length) {
                           c->name, c->hostname);
 
        if(c->protocol_minor >= 2)
-               return send_record(&c->sptps, 0, buffer, length);
+               return sptps_send_record(&c->sptps, 0, buffer, length);
 
        /* Add our data to buffer */
        if(c->status.encryptout) {
@@ -163,7 +163,7 @@ bool receive_meta(connection_t *c) {
        do {
                if(c->protocol_minor >= 2) {
                        logger(LOG_DEBUG, "Receiving %d bytes of SPTPS data", inlen);
-                       return receive_data(&c->sptps, bufp, inlen);
+                       return sptps_receive_data(&c->sptps, bufp, inlen);
                }
 
                if(!c->status.decryptin) {
index 65e9634..c91723b 100644 (file)
@@ -144,7 +144,7 @@ bool id_h(connection_t *c, char *request) {
                else
                        snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, myself->name);
 
-               return start_sptps(&c->sptps, c, c->outgoing, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
+               return sptps_start(&c->sptps, c, c->outgoing, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
        } else {
                return send_metakey(c);
        }
index 5088d65..395c92f 100644 (file)
@@ -85,7 +85,7 @@ static bool send_record_priv(sptps_t *s, uint8_t type, const char *data, uint16_
 }
 
 // Send an application record.
-bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) {
+bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) {
        // Sanity checks: application cannot send data before handshake is finished,
        // and only record types 0..127 are allowed.
        if(!s->outstate)
@@ -288,7 +288,7 @@ static bool receive_sig(sptps_t *s, const char *data, uint16_t len) {
 }
 
 // Force another Key EXchange (for testing purposes).
-bool force_kex(sptps_t *s) {
+bool sptps_force_kex(sptps_t *s) {
        if(!s->outstate || s->state != SPTPS_SECONDARY_KEX)
                return error(s, EINVAL, "Cannot force KEX in current state");
 
@@ -332,7 +332,7 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) {
 }
 
 // Receive incoming data. Check if it contains a complete record, if so, handle it.
-bool receive_data(sptps_t *s, const char *data, size_t len) {
+bool sptps_receive_data(sptps_t *s, const char *data, size_t len) {
        while(len) {
                // First read the 2 length bytes.
                if(s->buflen < 6) {
@@ -422,7 +422,7 @@ bool receive_data(sptps_t *s, const char *data, size_t len) {
 }
 
 // Start a SPTPS session.
-bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
+bool sptps_start(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
        // Initialise struct sptps
        memset(s, 0, sizeof *s);
 
@@ -453,7 +453,7 @@ bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_
 }
 
 // Stop a SPTPS session.
-bool stop_sptps(sptps_t *s) {
+bool sptps_stop(sptps_t *s) {
        // Clean up any resources.
        ecdh_free(&s->ecdh);
        free(s->inbuf);
index 17dfa9c..065c6a0 100644 (file)
@@ -76,10 +76,10 @@ typedef struct sptps {
        receive_record_t receive_record;
 } sptps_t;
 
-extern bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record);
-extern bool stop_sptps(sptps_t *s);
-extern bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len);
-extern bool receive_data(sptps_t *s, const char *data, size_t len);
-extern bool force_kex(sptps_t *s);
+extern bool sptps_start(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record);
+extern bool sptps_stop(sptps_t *s);
+extern bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len);
+extern bool sptps_receive_data(sptps_t *s, const char *data, size_t len);
+extern bool sptps_force_kex(sptps_t *s);
 
 #endif
index 6ab7dac..06d8dea 100644 (file)
@@ -118,7 +118,7 @@ int main(int argc, char *argv[]) {
        fprintf(stderr, "Keys loaded\n");
 
        sptps_t s;
-       if(!start_sptps(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record))
+       if(!sptps_start(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record))
                return 1;
 
        while(true) {
@@ -141,11 +141,11 @@ int main(int argc, char *argv[]) {
                        if(len == 0)
                                break;
                        if(buf[0] == '^')
-                               send_record(&s, SPTPS_HANDSHAKE, NULL, 0);
+                               sptps_send_record(&s, SPTPS_HANDSHAKE, NULL, 0);
                        else if(buf[0] == '$')
-                               force_kex(&s);
+                               sptps_force_kex(&s);
                        else
-                       if(!send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len))
+                       if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len))
                                return 1;
                }
 
@@ -162,10 +162,13 @@ int main(int argc, char *argv[]) {
                        char hex[len * 2 + 1];
                        bin2hex(buf, hex, len);
                        fprintf(stderr, "Received %zd bytes of data:\n%s\n", len, hex);
-                       if(!receive_data(&s, buf, len))
+                       if(!sptps_receive_data(&s, buf, len))
                                return 1;
                }
        }
 
+       if(!sptps_stop(&s))
+               return 1;
+
        return 0;
 }