Added lots of asserts, and split out the ip address from the connection object.

Still a lot of work remains and a massive network connection cleanup is needed.
This commit is contained in:
Jan Vidar Krey
2009-09-28 23:15:15 +02:00
parent a53c219f05
commit 69f6d811bf
11 changed files with 54 additions and 32 deletions

View File

@@ -290,7 +290,7 @@ static int command_version(struct hub_info* hub, struct hub_user* user, struct h
static int command_myip(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
{
char tmp[128];
snprintf(tmp, 128, "Your address is \"%s\"", net_con_get_peer_address(user->connection));
snprintf(tmp, 128, "Your address is \"%s\"", user_get_address(user));
return command_status(hub, user, cmd, tmp);
}
@@ -304,7 +304,7 @@ static int command_getip(struct hub_info* hub, struct hub_user* user, struct hub
if (!target)
return command_status_user_not_found(hub, user, cmd, nick);
snprintf(tmp, 128, "%s has address \"%s\"", nick, net_con_get_peer_address(user->connection));
snprintf(tmp, 128, "%s has address \"%s\"", nick, user_get_address(user));
return command_status(hub, user, cmd, tmp);
}
@@ -342,7 +342,7 @@ static int command_whoip(struct hub_info* hub, struct hub_user* user, struct hub
{
strcat(buffer, u->id.nick);
strcat(buffer, " (");
strcat(buffer, net_con_get_peer_address(u->connection));
strcat(buffer, user_get_address(u));
strcat(buffer, ")\n");
u = (struct hub_user*) list_get_next(users);
}

View File

@@ -1047,7 +1047,7 @@ void hub_logout_log(struct hub_info* hub, struct hub_user* user)
loginfo->time = time(NULL);
strcpy(loginfo->cid, user->id.cid);
strcpy(loginfo->nick, user->id.nick);
memcpy(&loginfo->addr, &user->connection->ipaddr, sizeof(struct ip_addr_encap));
memcpy(&loginfo->addr, &user->id.addr, sizeof(struct ip_addr_encap));
loginfo->reason = user->quit_reason;
list_append(hub->logout_info, loginfo);

View File

@@ -22,26 +22,26 @@
static void log_user_login(struct hub_user* u)
{
const char* cred = get_user_credential_string(u->credentials);
const char* addr = net_con_get_peer_address(u->connection);
const char* addr = user_get_address(u);
LOG_USER("LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, cred, u->user_agent);
}
static void log_user_login_error(struct hub_user* u, enum status_message msg)
{
const char* addr = net_con_get_peer_address(u->connection);
const char* addr = user_get_address(u);
const char* message = hub_get_status_message_log(u->hub, msg);
LOG_USER("LoginError %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message, u->user_agent);
}
static void log_user_logout(struct hub_user* u, const char* message)
{
const char* addr = net_con_get_peer_address(u->connection);
const char* addr = user_get_address(u);
LOG_USER("Logout %s/%s %s \"%s\" (%s)", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message);
}
static void log_user_nick_change(struct hub_user* u, const char* nick)
{
const char* addr = net_con_get_peer_address(u->connection);
const char* addr = user_get_address(u);
LOG_USER("NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
}

View File

@@ -186,7 +186,7 @@ static int check_required_login_flags(struct hub_info* hub, struct hub_user* use
*/
int check_network(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd)
{
const char* address = net_con_get_peer_address(user->connection);
const char* address = user_get_address(user);
/* Check for NAT override address */
if (acl_is_ip_nat_override(hub->acl, address))

View File

@@ -187,6 +187,14 @@ void net_event(struct net_connection* con, int event, void *arg)
struct hub_user* user = (struct hub_user*) arg;
int flag_close = 0;
if (event == NET_EVENT_DESTROYED)
{
printf("NET_EVENT_DESTROYED\n");
hub_free(user->connection);
user->connection = 0;
return;
}
#ifdef DEBUG_SENDQ
LOG_TRACE("net_event() : fd=%d, ev=%d, arg=%p", fd, (int) event, arg);
#endif

View File

@@ -197,7 +197,7 @@ int route_info_message(struct hub_info* hub, struct hub_user* u)
else
{
struct adc_message* cmd = adc_msg_copy(u->info);
const char* address = net_con_get_peer_address(u->connection);
const char* address = user_get_address(u);
struct hub_user* user = 0;
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);

View File

@@ -51,9 +51,11 @@ struct hub_user* user_create(struct hub_info* hub, int sd, struct ip_addr_encap*
user->recv_queue = hub_recvq_create();
user->connection = (struct net_connection*) hub_malloc(sizeof(struct net_connection));
net_con_initialize(user->connection, sd, addr, net_event, user, NET_EVENT_READ);
net_con_initialize(user->connection, sd, net_event, user, NET_EVENT_READ);
net_con_set_timeout(user->connection, TIMEOUT_CONNECTED);
memcpy(&user->id.addr, addr, sizeof(struct ip_addr_encap));
user_set_state(user, state_protocol);
return user;
}
@@ -344,4 +346,7 @@ const char* user_get_quit_reason_string(enum user_quit_reason reason)
return "unknown";
}
const char* user_get_address(struct hub_user* user)
{
return ip_convert_to_string(&user->id.addr);
}

View File

@@ -79,6 +79,7 @@ struct hub_user_info
sid_t sid; /** session ID */
char cid[MAX_CID_LEN+1]; /** global client ID */
char nick[MAX_NICK_LEN+1]; /** User's nick name */
struct ip_addr_encap addr; /** User's IP address */
};
/**
@@ -209,6 +210,8 @@ extern void user_support_add(struct hub_user* user, int fourcc);
*/
extern void user_support_remove(struct hub_user* user, int fourcc);
extern const char* user_get_address(struct hub_user* user);
/**
* Sets the nat override flag for a user, this allows users on the same
* subnet as a natted hub to spoof their IP in order to use active mode

View File

@@ -221,7 +221,7 @@ size_t uman_get_user_by_addr(struct hub_info* hub, struct linked_list* users, st
struct hub_user* user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
while (user)
{
if (ip_in_range(&user->connection->ipaddr, range))
if (ip_in_range(&user->id.addr, range))
{
list_append(users, user);
num++;