download checksum file directly from server
Remove assumption on small file to shortcircuit the redirect logic.master
							parent
							
								
									6a81079dc1
								
							
						
					
					
						commit
						6010fe62fd
					
				|  | @ -49,7 +49,7 @@ static void tip_client_release(struct ev_loop *loop, struct tip_client *cli) | |||
| 	free((void *)cli->path); | ||||
| 
 | ||||
| 	if (cli->method == TIP_METHOD_GET) { | ||||
| 		if (tip_client_large_file(cli)) { | ||||
| 		if (!tip_client_checksum_file(cli)) { | ||||
| 			num_clients--; | ||||
| 			if (!cli->redirect) | ||||
| 				tip_client_activate_pending(false); | ||||
|  | @ -192,7 +192,7 @@ static void tip_client_read_cb(struct ev_loop *loop, struct ev_io *io, int event | |||
| 	} | ||||
| 	return; | ||||
| shutdown: | ||||
| 	if (cli->size > FILE_SIZE_THRESHOLD) | ||||
| 	if (!tip_client_checksum_file(cli)) | ||||
| 		tip_client_redirect_create(cli); | ||||
| close: | ||||
| 	tip_client_release(loop, cli); | ||||
|  |  | |||
|  | @ -15,8 +15,6 @@ extern const char *root; | |||
| extern int max_clients; | ||||
| extern int num_clients; | ||||
| extern bool redirect; | ||||
| /* max_client logic only applies for files larger than 1024 bytes. */ | ||||
| #define FILE_SIZE_THRESHOLD 1024ULL | ||||
| 
 | ||||
| enum tip_client_state { | ||||
| 	TIP_CLIENT_PENDING		= 0, | ||||
|  | @ -50,6 +48,7 @@ struct tip_client { | |||
| 	enum tip_http_method	method; | ||||
| 	const char		*uri; | ||||
| 	const char		*path; | ||||
| 	bool			checksum; | ||||
| 	uint32_t		chunk; | ||||
| 	off_t			size; | ||||
| 	off_t			left; | ||||
|  | @ -67,9 +66,9 @@ static inline int tip_client_socket(const struct tip_client *cli) | |||
| 	return cli->io.fd; | ||||
| } | ||||
| 
 | ||||
| static inline bool tip_client_large_file(const struct tip_client *cli) | ||||
| static inline bool tip_client_checksum_file(const struct tip_client *cli) | ||||
| { | ||||
| 	return cli->size > FILE_SIZE_THRESHOLD; | ||||
| 	return cli->checksum; | ||||
| } | ||||
| 
 | ||||
| void tip_client_pending(struct tip_client *cli); | ||||
|  |  | |||
|  | @ -106,6 +106,12 @@ int tip_client_state_process_payload(struct tip_client *cli) | |||
| 		if (!redirect) | ||||
| 			break; | ||||
| 
 | ||||
| 		/* skip checksum files. */ | ||||
| 		if (strstr(uri, ".full.sum")) { | ||||
| 			cli->checksum = true; | ||||
| 			break; | ||||
| 		} | ||||
| 
 | ||||
| 		/* get chunk number from file extension, e.g. FILE.0 */ | ||||
| 		chunk = strchr(uri, '.'); | ||||
| 		if (chunk) { | ||||
|  | @ -150,7 +156,7 @@ int tip_client_state_process_payload(struct tip_client *cli) | |||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	if (tip_client_large_file(cli)) { | ||||
| 	if (!tip_client_checksum_file(cli)) { | ||||
| 		cli->allow_redirect = allow_redirect; | ||||
| 
 | ||||
| 		num_clients++; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue