chiark / gitweb /
site: transport peers: Break out transport_resolve_complete,_tardy
[secnet.git] / site.c
diff --git a/site.c b/site.c
index 379ab0d..afa85e8 100644 (file)
--- a/site.c
+++ b/site.c
@@ -208,6 +208,10 @@ static void transport_data_msgok(struct site *st, const struct comm_addr *a);
 static bool_t transport_compute_setupinit_peers(struct site *st,
         const struct comm_addr *configured_addr /* 0 if none or not found */,
         const struct comm_addr *prod_hint_addr /* 0 if none */);
+static void transport_resolve_complete(struct site *st,
+                                      const struct comm_addr *a);
+static void transport_resolve_complete_tardy(struct site *st,
+                                            const struct comm_addr *ca_use);
 static void transport_record_peer(struct site *st, transport_peers *peers,
                                  const struct comm_addr *addr, const char *m);
 
@@ -1182,8 +1186,7 @@ static void site_resolve_callback(void *sst, struct in_addr *address)
             * It's best to store it in st->peers now because we might
             * go via SENTMSG5, WAIT, and a MSG0, straight into using
             * the new key (without updating the data peer addrs). */
-           transport_record_peer(st,&st->peers,ca_use,"resolved data");
-           transport_record_peer(st,&st->setup_peers,ca_use,"resolved setup");
+           transport_resolve_complete(st,ca_use);
        } else if (st->local_mobile) {
            /* We can't let this rest because we may have a peer
             * address which will break in the future. */
@@ -1201,7 +1204,7 @@ static void site_resolve_callback(void *sst, struct in_addr *address)
        if (ca_use) {
            slog(st,LOG_SETUP_INIT,"resolution of %s completed tardily,"
                 " updating peer address(es)",st->address);
-           transport_record_peer(st,&st->peers,ca_use,"resolved tardily");
+           transport_resolve_complete_tardy(st,ca_use);
        } else if (st->local_mobile) {
            /* Not very good.  We should queue (another) renegotiation
             * so that we can update the peer address. */
@@ -1631,7 +1634,7 @@ static bool_t site_incoming(void *sst, struct buffer_if *buf,
            if (process_msg1(st,buf,source,&named_msg)) {
                slog(st,LOG_SETUP_INIT,"key setup initiated by peer");
                bool_t entered=enter_new_state(st,SITE_SENTMSG2);
-               if (entered && st->address)
+               if (entered && st->address && st->local_mobile)
                    /* We must do this as the very last thing, because
                       the resolver callback might reenter us. */
                    ensure_resolving(st);
@@ -2145,6 +2148,17 @@ static void transport_peers_copy(struct site *st, transport_peers *dst,
                          src->npeers, &src->peers->addr, sizeof(*src->peers));
 }
 
+static void transport_resolve_complete(struct site *st,
+                                      const struct comm_addr *ca_use) {
+    transport_record_peer(st,&st->peers,ca_use,"resolved data");
+    transport_record_peer(st,&st->setup_peers,ca_use,"resolved setup");
+}
+
+static void transport_resolve_complete_tardy(struct site *st,
+                                            const struct comm_addr *ca_use) {
+    transport_record_peer(st,&st->peers,ca_use,"resolved tardily");
+}
+
 void transport_xmit(struct site *st, transport_peers *peers,
                    struct buffer_if *buf, bool_t candebug) {
     int slot;