New test from ISIS implemented - test_lookup_sent correct
This commit is contained in:
+43
-18
@@ -54,14 +54,23 @@ neighbor check_neighborhood(uint16_t);
|
||||
|
||||
uint16_t hash_uri(const char *uri){
|
||||
char *uri_ptr = (char*)uri;
|
||||
char dynamic[] = "/dynamic/";
|
||||
char static_[] = "/static/";
|
||||
/*
|
||||
char *it = (char *)uri;
|
||||
|
||||
if(strstr(uri, dynamic)) uri_ptr += strlen(dynamic);
|
||||
elif(strstr(uri, static_)) uri_ptr += strlen(static_);
|
||||
elif(uri[0] == '/') uri_ptr++;
|
||||
// shift uri_ptr to last '/'
|
||||
while(*it)
|
||||
{
|
||||
if (*it == '/') uri_ptr = it++;
|
||||
it++;
|
||||
}
|
||||
|
||||
return pseudo_hash((unsigned char *)uri_ptr, strlen(uri_ptr));
|
||||
// skip last '/'
|
||||
if (*uri_ptr == '/') uri_ptr++;
|
||||
|
||||
if (!*uri_ptr) return -1;
|
||||
*/
|
||||
|
||||
return pseudo_hash((const unsigned char *)uri_ptr, strlen(uri_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +96,17 @@ void send_reply(int conn, struct request *request) {
|
||||
// const char *resource = get(request->uri, resources, MAX_RESOURCES, &resource_length);
|
||||
|
||||
uint16_t resource_hash = hash_uri(request->uri);
|
||||
|
||||
fprintf(stderr, "Resource hash: %u\n", resource_hash);
|
||||
|
||||
if (resource_hash == -1)
|
||||
{
|
||||
printf("404\n");
|
||||
reply = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n";
|
||||
offset = strlen(reply);
|
||||
goto direct_send;
|
||||
}
|
||||
|
||||
neighbor responsible = check_neighborhood(resource_hash);
|
||||
|
||||
lookup_request *req = find_lookup(resource_hash);
|
||||
@@ -108,25 +128,25 @@ void send_reply(int conn, struct request *request) {
|
||||
}
|
||||
|
||||
if (responsible == res) {
|
||||
sprintf(reply, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
|
||||
printf("Responsible - 404\n");
|
||||
reply = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n";
|
||||
offset = strlen(reply);
|
||||
printf("200\n");
|
||||
}
|
||||
elif(responsible == res_303)
|
||||
{
|
||||
int suc_id = _SUCC_ID;
|
||||
if (resource_hash <= suc_id || suc_id >= 0 && suc_id < _NODE_ID)
|
||||
{
|
||||
printf("404\n");
|
||||
reply = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n";
|
||||
offset = strlen(reply);
|
||||
}
|
||||
else
|
||||
if ((_NODE_ID < suc_id && resource_hash > _NODE_ID && resource_hash <= suc_id) || (_NODE_ID > suc_id && (resource_hash > _NODE_ID || resource_hash <= suc_id)))
|
||||
{
|
||||
sprintf(reply, "HTTP/1.1 303 See Other\r\nLocation: http://%s:%d%s\r\nContent-Length: 0\r\n\r\n", _SUCC_IP, _SUCC_PORT, request->uri);
|
||||
offset = strlen(reply);
|
||||
printf("303\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("404\n");
|
||||
reply = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n";
|
||||
offset = strlen(reply);
|
||||
}
|
||||
}
|
||||
elif(responsible == not_res)
|
||||
{
|
||||
@@ -167,6 +187,8 @@ void send_reply(int conn, struct request *request) {
|
||||
offset = strlen(reply);
|
||||
}
|
||||
|
||||
direct_send: // ... do goto, yes you read that right ;)
|
||||
|
||||
// Send the reply back to the client
|
||||
if (send(conn, reply, offset, 0) == -1) {
|
||||
perror("send");
|
||||
@@ -455,10 +477,12 @@ static void handle_udp_request(int _sock){
|
||||
{
|
||||
const neighbor responsibility = check_neighborhood(lr.hash_id);
|
||||
|
||||
/* res is handles upfront by not res and suc responsibility check
|
||||
if (responsibility == res) {
|
||||
lookup_request_init(&backfire, 1, _NODE_ID, inet_addr(_NODE_IP), _NODE_PORT, _PRED_ID);
|
||||
}
|
||||
elif (responsibility == not_res) {
|
||||
*/
|
||||
if (responsibility == not_res) {
|
||||
// is succ responsible
|
||||
if (lr.hash_id <= suc_id)
|
||||
{
|
||||
@@ -466,14 +490,15 @@ static void handle_udp_request(int _sock){
|
||||
}
|
||||
else
|
||||
{
|
||||
lookup_request_init(&backfire, 1, suc_id, suc_ip, _SUCC_PORT, _NODE_ID);
|
||||
// lookup_request_init(&backfire, 0, suc_id, suc_ip, _SUCC_PORT, _NODE_ID);
|
||||
clone_lookup_request(&backfire, &lr);
|
||||
|
||||
callback_ip = &suc_ip_s.s_addr;
|
||||
callback_port = _SUCC_PORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
call_network(&backfire, *callback_ip, callback_port);
|
||||
//call_network(&backfire, *callback_ip, callback_port);
|
||||
}
|
||||
elif (lr.message_type == 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user