|
|
|
|
@ -163,8 +163,6 @@ static void fixture_init(struct fixture* f) {
|
|
|
|
|
f->source.address_profile.mapping = ADDRESS_MAP_DEPENDENT; |
|
|
|
|
f->source.address_profile.inbound = ADDRESS_IN_CONTACT; |
|
|
|
|
f->source.address_profile.source = ADDRESS_SOURCE_ETCP; |
|
|
|
|
f->source.address_profile.evidence_id = 1; |
|
|
|
|
f->source.address_profile.checked_at = 1; |
|
|
|
|
f->source.nat_addr = f->source.local_addr; |
|
|
|
|
snprintf(f->source.name, sizeof(f->source.name), "source"); |
|
|
|
|
f->inst.etcp_sockets = &f->source; |
|
|
|
|
@ -388,7 +386,7 @@ static void test_fallback(void) {
|
|
|
|
|
struct ETCP_SOCKET* duplicate = test_etcp_bound_socket(owner, "duplicate"); |
|
|
|
|
wait_source(&nf, socket, ADDRESS_SOURCE_STUN); wait_source(&nf, duplicate, ADDRESS_SOURCE_STUN); |
|
|
|
|
assert(socket->address_profile.mapping == ADDRESS_MAP_EIM && socket->address_profile.inbound == ADDRESS_IN_OPEN); |
|
|
|
|
assert(socket->address_profile.evidence_id == duplicate->address_profile.evidence_id); |
|
|
|
|
assert(!memcmp(&socket->address_profile, &duplicate->address_profile, sizeof(socket->address_profile))); |
|
|
|
|
assert(!socket->nat_addr.ss_family && !duplicate->nat_addr.ss_family); |
|
|
|
|
struct nat_check_status status; assert(!nat_detection_get_status(owner->nat_det, socket, &status)); |
|
|
|
|
assert(status.reason == NAT_REASON_NO_OBSERVER && status.fallback_allowed); |
|
|
|
|
@ -406,19 +404,25 @@ static void test_fallback(void) {
|
|
|
|
|
nat_fixture_connect(&nf, observer, "udp", helper); nat_detection_request_check_all(owner->nat_det); |
|
|
|
|
wait_source(&nf, socket, ADDRESS_SOURCE_ETCP); wait_source(&nf, duplicate, ADDRESS_SOURCE_ETCP); |
|
|
|
|
assert(socket->address_profile.mapping == ADDRESS_MAP_UNCHANGED && socket->address_profile.inbound == ADDRESS_IN_OPEN); |
|
|
|
|
uint64_t evidence = socket->address_profile.evidence_id; |
|
|
|
|
assert(!nat_detection_get_status(owner->nat_det, socket, &status)); |
|
|
|
|
uint64_t round = status.round; |
|
|
|
|
struct address_profile measured = socket->address_profile; |
|
|
|
|
struct stun_nat_result prior, next; |
|
|
|
|
assert(!stun_nat_get_socket_result(owner, socket, &prior)); stun_nat_recheck(owner); |
|
|
|
|
end = get_time_tb() + 3000000; |
|
|
|
|
do { test_clock_poll(nf.ua, 10000); assert(!stun_nat_get_socket_result(owner, socket, &next)); } |
|
|
|
|
while (get_time_tb() < end && next.status == STUN_NAT_PENDING); |
|
|
|
|
assert(next.mapping == STUN_MAP_EIM && next.evidence_id != prior.evidence_id); |
|
|
|
|
assert(socket->address_profile.source == ADDRESS_SOURCE_ETCP && socket->address_profile.evidence_id == evidence); |
|
|
|
|
assert(!memcmp(&socket->address_profile, &measured, sizeof(measured))); |
|
|
|
|
nat_detection_request_check_all(owner->nat_det); end = get_time_tb() + 300000; |
|
|
|
|
do { test_clock_poll(nf.ua, 10000); } |
|
|
|
|
while (get_time_tb() < end && socket->address_profile.evidence_id == evidence); |
|
|
|
|
assert(socket->address_profile.source == ADDRESS_SOURCE_ETCP && socket->address_profile.evidence_id != evidence); |
|
|
|
|
assert(socket->address_profile.mapping == ADDRESS_MAP_UNCHANGED && socket->address_profile.inbound == ADDRESS_IN_UNKNOWN); |
|
|
|
|
do { test_clock_poll(nf.ua, 10000); assert(!nat_detection_get_status(owner->nat_det, socket, &status)); } |
|
|
|
|
while (get_time_tb() < end && (status.round == round || status.phase)); |
|
|
|
|
assert(status.round != round && !status.phase); |
|
|
|
|
assert(!memcmp(&socket->address_profile, &measured, sizeof(measured))); |
|
|
|
|
/* Прошедшие пять минут не сбрасывают последний успешный ETCP. */ |
|
|
|
|
uint64_t timestamp = snapshot->timestamp; |
|
|
|
|
test_clock_run_for(nf.ua, 3000001); |
|
|
|
|
assert(!memcmp(&socket->address_profile, &measured, sizeof(measured)) && snapshot->timestamp == timestamp); |
|
|
|
|
for (unsigned i = 0; i < 6; i++) { |
|
|
|
|
assert(!uasync_remove_socket_t(nf.ua, server.endpoints[i].fd)); socket_close_wrapper(server.endpoints[i].fd); |
|
|
|
|
} |
|
|
|
|
|