code adjust for pull request #673
parent
1809d46020
commit
bfb3e9f887
|
|
@ -31,8 +31,7 @@
|
|||
#include "client_global.h"
|
||||
#include "fastcommon/base64.h"
|
||||
|
||||
static struct base64_context the_base64_context;
|
||||
static int the_base64_context_inited = 0;
|
||||
static int g_base64_context_inited = 0;
|
||||
|
||||
#define FDFS_SPLIT_GROUP_NAME_AND_FILENAME(file_id) \
|
||||
char in_file_id[FDFS_GROUP_NAME_MAX_LEN + 128]; \
|
||||
|
|
@ -383,17 +382,17 @@ int storage_query_file_info_ex(ConnectionInfo *pTrackerServer, \
|
|||
result = EINVAL;
|
||||
}
|
||||
|
||||
if (!the_base64_context_inited)
|
||||
if (!g_base64_context_inited)
|
||||
{
|
||||
the_base64_context_inited = 1;
|
||||
base64_init_ex(&the_base64_context, 0, '-', '_', '.');
|
||||
g_base64_context_inited = 1;
|
||||
base64_init_ex(&g_fdfs_base64_context, 0, '-', '_', '.');
|
||||
}
|
||||
|
||||
memset(buff, 0, sizeof(buff));
|
||||
if (filename_len >= FDFS_LOGIC_FILE_PATH_LEN \
|
||||
+ FDFS_FILENAME_BASE64_LENGTH + FDFS_FILE_EXT_NAME_MAX_LEN + 1)
|
||||
{
|
||||
base64_decode_auto(&the_base64_context, (char *)filename + \
|
||||
base64_decode_auto(&g_fdfs_base64_context, (char *)filename + \
|
||||
FDFS_LOGIC_FILE_PATH_LEN, FDFS_FILENAME_BASE64_LENGTH, \
|
||||
buff, &buff_len);
|
||||
}
|
||||
|
|
@ -2139,10 +2138,10 @@ int fdfs_get_file_info_ex(const char *group_name, const char *remote_filename, \
|
|||
char buff[64];
|
||||
|
||||
memset(pFileInfo, 0, sizeof(FDFSFileInfo));
|
||||
if (!the_base64_context_inited)
|
||||
if (!g_base64_context_inited)
|
||||
{
|
||||
the_base64_context_inited = 1;
|
||||
base64_init_ex(&the_base64_context, 0, '-', '_', '.');
|
||||
g_base64_context_inited = 1;
|
||||
base64_init_ex(&g_fdfs_base64_context, 0, '-', '_', '.');
|
||||
}
|
||||
|
||||
filename_len = strlen(remote_filename);
|
||||
|
|
@ -2156,7 +2155,7 @@ int fdfs_get_file_info_ex(const char *group_name, const char *remote_filename, \
|
|||
}
|
||||
|
||||
memset(buff, 0, sizeof(buff));
|
||||
base64_decode_auto(&the_base64_context, (char *)remote_filename + \
|
||||
base64_decode_auto(&g_fdfs_base64_context, (char *)remote_filename + \
|
||||
FDFS_LOGIC_FILE_PATH_LEN, FDFS_FILENAME_BASE64_LENGTH, \
|
||||
buff, &buff_len);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ Version g_fdfs_version = {6, 10, 0};
|
|||
bool g_use_connection_pool = false;
|
||||
ConnectionPool g_connection_pool;
|
||||
int g_connection_pool_max_idle_time = 3600;
|
||||
struct base64_context g_fdfs_base64_context;
|
||||
|
||||
/*
|
||||
data filename format:
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@
|
|||
#define _FDFS_GLOBAL_H
|
||||
|
||||
#include "fastcommon/common_define.h"
|
||||
#include "fastcommon/base64.h"
|
||||
#include "fastcommon/connection_pool.h"
|
||||
#include "sf/sf_global.h"
|
||||
#include "fdfs_define.h"
|
||||
#include "fastcommon/connection_pool.h"
|
||||
|
||||
#define FDFS_FILE_EXT_NAME_MAX_LEN 6
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ extern Version g_fdfs_version;
|
|||
extern bool g_use_connection_pool;
|
||||
extern ConnectionPool g_connection_pool;
|
||||
extern int g_connection_pool_max_idle_time;
|
||||
extern struct base64_context g_fdfs_base64_context;
|
||||
|
||||
int fdfs_check_data_filename(const char *filename, const int len);
|
||||
int fdfs_gen_slave_filename(const char *master_filename, \
|
||||
|
|
|
|||
|
|
@ -177,7 +177,9 @@ int fdht_connect_server_nb(FDHTServerInfo *pServer, const int connect_timeout)
|
|||
if (is_ipv6_addr(pServer->ip_addr))
|
||||
{
|
||||
pServer->sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
pServer->sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +228,9 @@ int fdht_connect_server(FDHTServerInfo *pServer)
|
|||
if (is_ipv6_addr(pServer->ip_addr))
|
||||
{
|
||||
pServer->sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
pServer->sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,27 +226,23 @@ static int tracker_get_my_server_id()
|
|||
char ip_str[256];
|
||||
bool flag = false;
|
||||
|
||||
if (inet_pton(AF_INET, g_tracker_client_ip.ips[0].address, &ipv4_addr) == 1)
|
||||
if (inet_pton(AF_INET, g_tracker_client_ip.ips[0].
|
||||
address, &ipv4_addr) == 1)
|
||||
{
|
||||
g_server_id_in_filename = ipv4_addr.s_addr;
|
||||
flag = true;
|
||||
}
|
||||
else if(inet_pton(AF_INET6, g_tracker_client_ip.ips[0].address, &ipv6_addr) == 1)
|
||||
else if (inet_pton(AF_INET6, g_tracker_client_ip.ips[0].
|
||||
address, &ipv6_addr) == 1)
|
||||
{
|
||||
char buffer[INET6_ADDRSTRLEN];
|
||||
const char *result = inet_ntop(AF_INET6, &ipv6_addr, buffer, INET6_ADDRSTRLEN);
|
||||
|
||||
if (result != NULL) {
|
||||
memcpy(&g_server_id_in_filename, &ipv6_addr, sizeof(in_addr_64_t));
|
||||
|
||||
g_server_id_in_filename = *((in_addr_64_t *)((char *)&ipv6_addr + 8));
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call inet_pton for ip: %s fail", \
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"call inet_pton for ip: %s fail",
|
||||
__LINE__, g_tracker_client_ip.ips[0].address);
|
||||
g_server_id_in_filename = INADDR_NONE;
|
||||
}
|
||||
|
|
@ -277,22 +273,25 @@ static int tracker_get_my_server_id()
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if (is_ipv6_addr(g_tracker_client_ip.ips[0].address))
|
||||
{
|
||||
fdfs_ip_to_shortcode(g_tracker_client_ip.ips[0].address,
|
||||
g_my_server_id_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_my_server_id_str, sizeof(g_my_server_id_str), "%s",
|
||||
g_tracker_client_ip.ips[0].address);
|
||||
}
|
||||
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if(is_ipv6_addr(g_tracker_client_ip.ips[0].address)){
|
||||
snprintf(g_my_server_id_str, sizeof(g_my_server_id_str), "%s",
|
||||
fdfs_ip_to_shortcode(g_tracker_client_ip.ips[0].address, FDFS_DEFAULT_STORAGE_ID_LEN));
|
||||
}
|
||||
|
||||
fdfs_multi_ips_to_string(&g_tracker_client_ip,
|
||||
ip_str, sizeof(ip_str));
|
||||
logInfo("file: "__FILE__", line: %d, "
|
||||
"tracker_client_ip: %s, my_server_id_str: %s, "
|
||||
"g_server_id_in_filename: %lu", __LINE__,
|
||||
"g_server_id_in_filename: %"PRIu64, __LINE__,
|
||||
ip_str, g_my_server_id_str, g_server_id_in_filename);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#include "tracker_proto.h"
|
||||
|
||||
FDFSStorePaths g_fdfs_store_paths = {0, NULL};
|
||||
struct base64_context g_fdfs_base64_context;
|
||||
BufferInfo g_zero_buffer = {NULL, 0, 0};
|
||||
|
||||
int trunk_shared_init()
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
extern FDFSStorePaths g_fdfs_store_paths; //file store paths
|
||||
extern struct base64_context g_fdfs_base64_context; //base64 context
|
||||
extern BufferInfo g_zero_buffer; //zero buffer for reset
|
||||
|
||||
typedef int (*stat_func)(const char *filename, struct stat *buf);
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
|
|||
char *group_name;
|
||||
char *pHost;
|
||||
char *pPort;
|
||||
char *pTmp;
|
||||
char *pSquare;
|
||||
FDFSStorageIdInfo *pStorageIdInfo;
|
||||
char error_info[256];
|
||||
int alloc_bytes;
|
||||
|
|
@ -430,20 +430,33 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
|
|||
pHost++;
|
||||
}
|
||||
|
||||
// 处理IPv6的前'['括号的问题
|
||||
pTmp = strchr(pHost, '[');
|
||||
if (pTmp != NULL)
|
||||
if (*pHost == '[') //IPv6 address
|
||||
{
|
||||
pHost++;
|
||||
pHost++; //skip [
|
||||
pSquare = strchr(pHost, ']');
|
||||
if (pSquare == NULL)
|
||||
{
|
||||
result = EINVAL;
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"config file: %s, line no: %d, invalid IPv6 "
|
||||
"address: %s", __LINE__, pStorageIdsFilename,
|
||||
i + 1, pHost - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
pPort = strchr(pHost, ']');
|
||||
if(pPort != NULL){
|
||||
*pPort = '\0';
|
||||
pPort++; // ]
|
||||
pPort++; // :
|
||||
*pSquare = '\0';
|
||||
pPort = pSquare + 1;
|
||||
if (*pPort == ':')
|
||||
{
|
||||
pStorageIdInfo->port = atoi(pPort + 1);
|
||||
}else {
|
||||
}
|
||||
else
|
||||
{
|
||||
pStorageIdInfo->port = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pPort = strchr(pHost, ':');
|
||||
if (pPort != NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -436,41 +436,41 @@ void fdfs_set_log_rotate_size(LogContext *pContext, const int64_t log_rotate_siz
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void deleteChar(char* str, int index) {
|
||||
int len = strlen(str);
|
||||
int i=0;
|
||||
|
||||
if (index >= 0 && index < len) {
|
||||
for (i = index; i < len - 1; i++) {
|
||||
str[i] = str[i + 1];
|
||||
}
|
||||
str[len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
int fdfs_parse_server_info_ex(char *server_str, const int default_port,
|
||||
TrackerServerInfo *pServer, const bool resolve)
|
||||
{
|
||||
char *pSquare;
|
||||
char *pColon;
|
||||
char *pTmp;
|
||||
char *hosts[FDFS_MULTI_IP_MAX_COUNT];
|
||||
ConnectionInfo *conn;
|
||||
int port;
|
||||
int i;
|
||||
|
||||
memset(pServer, 0, sizeof(TrackerServerInfo));
|
||||
|
||||
if((pTmp=strchr(server_str,'[') )!=NULL){
|
||||
deleteChar(server_str,0);
|
||||
if (*server_str == '[')
|
||||
{
|
||||
server_str++;
|
||||
if ((pSquare=strchr(server_str, ']')) == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"host \"%s\" is invalid",
|
||||
__LINE__, server_str - 1);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if((pColon=strchr(server_str, ']') ) != NULL){
|
||||
*pColon = '\0';
|
||||
pColon++; // ]
|
||||
port = atoi(pColon + 1);
|
||||
}else {
|
||||
if ((pColon=strrchr(server_str, ':')) == NULL)
|
||||
*pSquare = '\0';
|
||||
pColon = pSquare + 1; //skip ]
|
||||
if (*pColon != ':')
|
||||
{
|
||||
pColon = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pColon = strrchr(server_str, ':');
|
||||
}
|
||||
|
||||
if (pColon == NULL)
|
||||
{
|
||||
logInfo("file: "__FILE__", line: %d, "
|
||||
"no port part in %s, set port to %d",
|
||||
|
|
@ -482,7 +482,6 @@ int fdfs_parse_server_info_ex(char *server_str, const int default_port,
|
|||
*pColon = '\0';
|
||||
port = atoi(pColon + 1);
|
||||
}
|
||||
}
|
||||
|
||||
conn = pServer->connections;
|
||||
pServer->count = splitEx(server_str, ',',
|
||||
|
|
@ -808,40 +807,12 @@ void fdfs_set_server_info_ex(TrackerServerInfo *pServer,
|
|||
}
|
||||
}
|
||||
|
||||
char* fdfs_ip_to_shortcode(const char* ipAddr, int shortCodeLength){
|
||||
char* shortCode = (char*) malloc(sizeof(char) * (shortCodeLength + 1));
|
||||
memset(shortCode, 0, sizeof(char) * (shortCodeLength + 1));
|
||||
char *fdfs_ip_to_shortcode(const char *ipAddr, char *shortCode)
|
||||
{
|
||||
int64_t crc64;
|
||||
int len;
|
||||
|
||||
char md5Hex[33];
|
||||
memset(md5Hex, 0, sizeof(char) * 33);
|
||||
int nLen = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (nLen < shortCodeLength) {
|
||||
MD5_CTX context;
|
||||
|
||||
my_md5_init(&context);
|
||||
my_md5_update(&context, (unsigned char*)md5Hex, strlen(md5Hex));
|
||||
my_md5_update(&context, (unsigned char*)ipAddr, strlen(ipAddr));
|
||||
unsigned char digest[16];
|
||||
my_md5_final(digest, &context);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
char hex[3];
|
||||
sprintf(hex, "%02x", digest[i]);
|
||||
for (j = 0; j < 2; j++) {
|
||||
char c = hex[j];
|
||||
if (c != '/' && c != '+') {
|
||||
shortCode[nLen++] = tolower(c);
|
||||
if (nLen == shortCodeLength) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nLen == shortCodeLength) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return shortCode;
|
||||
crc64 = CRC32_ex(ipAddr, strlen(ipAddr), CRC32_XINIT);
|
||||
return base64_encode(&g_fdfs_base64_context, (const char *)&crc64,
|
||||
sizeof(crc64), shortCode, &len);
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ void fdfs_set_server_info(TrackerServerInfo *pServer,
|
|||
void fdfs_set_server_info_ex(TrackerServerInfo *pServer,
|
||||
const FDFSMultiIP *ip_addrs, const int port);
|
||||
|
||||
char* fdfs_ip_to_shortcode(const char* ipAddr, int shortCodeLength);
|
||||
char *fdfs_ip_to_shortcode(const char *ipAddr, char *shortCode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ int main(int argc, char *argv[])
|
|||
return result;
|
||||
}
|
||||
|
||||
base64_init_ex(&g_base64_context, 0, '-', '_', '.');
|
||||
base64_init_ex(&g_fdfs_base64_context, 0, '-', '_', '.');
|
||||
if ((result=set_rand_seed()) != 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ FDFSStorageReservedSpace g_storage_reserved_space = { \
|
|||
int g_allow_ip_count = 0;
|
||||
in_addr_64_t *g_allow_ip_addrs = NULL;
|
||||
|
||||
struct base64_context g_base64_context;
|
||||
|
||||
bool g_storage_ip_changed_auto_adjust = true;
|
||||
bool g_use_storage_id = false; //if use storage ID instead of IP address
|
||||
byte g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS; //id type of the storage server in the filename
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ extern int g_check_active_interval; //check storage server alive every interval
|
|||
|
||||
extern int g_allow_ip_count; /* -1 means match any ip address */
|
||||
extern in_addr_64_t *g_allow_ip_addrs; /* sorted array, asc order */
|
||||
extern struct base64_context g_base64_context;
|
||||
|
||||
extern bool g_storage_ip_changed_auto_adjust;
|
||||
extern bool g_use_storage_id; //identify storage by ID instead of IP address
|
||||
|
|
|
|||
|
|
@ -3181,10 +3181,14 @@ static FDFSStorageDetail *tracker_mem_get_active_http_server_by_ip( \
|
|||
memset(&target_storage, 0, sizeof(target_storage));
|
||||
if (!g_use_storage_id)
|
||||
{
|
||||
strcpy(target_storage.id, ip_addr);
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if(is_ipv6_addr(ip_addr)){
|
||||
strcpy(target_storage.id, fdfs_ip_to_shortcode(ip_addr, FDFS_DEFAULT_STORAGE_ID_LEN));
|
||||
if (is_ipv6_addr(ip_addr))
|
||||
{
|
||||
fdfs_ip_to_shortcode(ip_addr, target_storage.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(target_storage.id, ip_addr);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -3243,7 +3247,7 @@ static FDFSStorageDetail *tracker_mem_get_active_http_server_by_id( \
|
|||
FDFSStorageDetail *tracker_mem_get_storage_by_ip(FDFSGroupInfo *pGroup, \
|
||||
const char *ip_addr)
|
||||
{
|
||||
const char *storage_id;
|
||||
FDFSStorageId storage_id;
|
||||
|
||||
if (g_use_storage_id)
|
||||
{
|
||||
|
|
@ -3254,18 +3258,23 @@ FDFSStorageDetail *tracker_mem_get_storage_by_ip(FDFSGroupInfo *pGroup, \
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
storage_id = pStorageIdInfo->id;
|
||||
storage_id.ptr = pStorageIdInfo->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
storage_id = ip_addr;
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if(is_ipv6_addr(ip_addr)){
|
||||
storage_id = fdfs_ip_to_shortcode(ip_addr, FDFS_DEFAULT_STORAGE_ID_LEN);
|
||||
if (is_ipv6_addr(ip_addr))
|
||||
{
|
||||
storage_id.ptr = fdfs_ip_to_shortcode(ip_addr,
|
||||
storage_id.holder);
|
||||
}
|
||||
else
|
||||
{
|
||||
storage_id.ptr = (char *)ip_addr;
|
||||
}
|
||||
}
|
||||
|
||||
return tracker_mem_get_storage(pGroup, storage_id);
|
||||
return tracker_mem_get_storage(pGroup, storage_id.ptr);
|
||||
}
|
||||
|
||||
FDFSStorageDetail *tracker_mem_get_storage(FDFSGroupInfo *pGroup, \
|
||||
|
|
@ -3658,7 +3667,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
|||
const bool bNeedLock, bool *bInserted)
|
||||
{
|
||||
int result;
|
||||
const char *storage_id;
|
||||
FDFSStorageId storage_id;
|
||||
FDFSStorageIdInfo *pStorageIdInfo;
|
||||
FDFSMultiIP multi_ip;
|
||||
|
||||
|
|
@ -3706,7 +3715,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
|||
multi_ip = pStorageIdInfo->ip_addrs;
|
||||
}
|
||||
|
||||
storage_id = id;
|
||||
storage_id.ptr = (char *)id;
|
||||
}
|
||||
else if (g_use_storage_id)
|
||||
{
|
||||
|
|
@ -3722,14 +3731,18 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
|||
}
|
||||
|
||||
multi_ip = pStorageIdInfo->ip_addrs;
|
||||
storage_id = pStorageIdInfo->id;
|
||||
storage_id.ptr = pStorageIdInfo->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
storage_id = ip_addr;
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if(is_ipv6_addr(ip_addr)){
|
||||
storage_id = fdfs_ip_to_shortcode(ip_addr, FDFS_DEFAULT_STORAGE_ID_LEN);
|
||||
if (is_ipv6_addr(ip_addr))
|
||||
{
|
||||
storage_id.ptr = fdfs_ip_to_shortcode(ip_addr, storage_id.holder);
|
||||
}
|
||||
else
|
||||
{
|
||||
storage_id.ptr = (char *)ip_addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3746,7 +3759,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
|||
{
|
||||
result = 0;
|
||||
*bInserted = false;
|
||||
*ppStorageServer = tracker_mem_get_storage(pGroup, storage_id);
|
||||
*ppStorageServer = tracker_mem_get_storage(pGroup, storage_id.ptr);
|
||||
if (*ppStorageServer != NULL)
|
||||
{
|
||||
if (g_use_storage_id)
|
||||
|
|
@ -3775,7 +3788,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
|||
|
||||
*ppStorageServer = *(pGroup->all_servers + pGroup->count);
|
||||
snprintf((*ppStorageServer)->id, FDFS_STORAGE_ID_MAX_SIZE,
|
||||
"%s", storage_id);
|
||||
"%s", storage_id.ptr);
|
||||
(*ppStorageServer)->ip_addrs = multi_ip;
|
||||
if (g_use_storage_id)
|
||||
{
|
||||
|
|
@ -4406,7 +4419,7 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
FDFSStorageDetail **ppServer;
|
||||
FDFSStorageDetail **ppEnd;
|
||||
FDFSStorageIdInfo *pStorageIdInfo;
|
||||
const char *storage_id;
|
||||
FDFSStorageId storage_id;
|
||||
|
||||
tracker_mem_file_lock();
|
||||
|
||||
|
|
@ -4502,17 +4515,20 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
pClientInfo->pGroup->group_name, ip_addr);
|
||||
return ENOENT;
|
||||
}
|
||||
storage_id = pStorageIdInfo->id;
|
||||
storage_id.ptr = pStorageIdInfo->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
pStorageIdInfo = NULL;
|
||||
storage_id = ip_addr;
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if(is_ipv6_addr(ip_addr)){
|
||||
storage_id = fdfs_ip_to_shortcode(ip_addr, FDFS_DEFAULT_STORAGE_ID_LEN);
|
||||
if (is_ipv6_addr(ip_addr))
|
||||
{
|
||||
storage_id.ptr = fdfs_ip_to_shortcode(ip_addr, storage_id.holder);
|
||||
}
|
||||
else
|
||||
{
|
||||
storage_id.ptr = (char *)ip_addr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (pClientInfo->pGroup->storage_port == 0)
|
||||
|
|
@ -4533,7 +4549,7 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
for (ppServer=pClientInfo->pGroup->all_servers; \
|
||||
ppServer<ppEnd; ppServer++)
|
||||
{
|
||||
if (strcmp((*ppServer)->id, storage_id) == 0)
|
||||
if (strcmp((*ppServer)->id, storage_id.ptr) == 0)
|
||||
{
|
||||
(*ppServer)->storage_port = \
|
||||
pJoinBody->storage_port;
|
||||
|
|
@ -4591,7 +4607,7 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
for (ppServer=pClientInfo->pGroup->all_servers; \
|
||||
ppServer<ppEnd; ppServer++)
|
||||
{
|
||||
if (strcmp((*ppServer)->id, storage_id) == 0)
|
||||
if (strcmp((*ppServer)->id, storage_id.ptr) == 0)
|
||||
{
|
||||
(*ppServer)->storage_http_port = \
|
||||
pJoinBody->storage_http_port;
|
||||
|
|
@ -4641,7 +4657,8 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
__LINE__, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
pStorageServer = tracker_mem_get_storage(pClientInfo->pGroup, storage_id);
|
||||
pStorageServer = tracker_mem_get_storage(pClientInfo->pGroup,
|
||||
storage_id.ptr);
|
||||
if (pthread_mutex_unlock(&mem_thread_lock) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
|
|
@ -4670,8 +4687,8 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
}
|
||||
}
|
||||
|
||||
if ((result=tracker_mem_add_storage(pClientInfo, storage_id, ip_addr,
|
||||
bNeedSleep, true, &bStorageInserted)) != 0)
|
||||
if ((result=tracker_mem_add_storage(pClientInfo, storage_id.ptr,
|
||||
ip_addr, bNeedSleep, true, &bStorageInserted)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
@ -5666,7 +5683,7 @@ int tracker_mem_get_storage_by_filename(const byte cmd,FDFS_DOWNLOAD_TYPE_PARAM\
|
|||
char name_buff[64];
|
||||
int decoded_len;
|
||||
|
||||
base64_decode_auto(&g_base64_context, (char *)filename + \
|
||||
base64_decode_auto(&g_fdfs_base64_context, (char *)filename + \
|
||||
FDFS_LOGIC_FILE_PATH_LEN, FDFS_FILENAME_BASE64_LENGTH, \
|
||||
name_buff, &decoded_len);
|
||||
storage_ip = ntohl(buff2int(name_buff));
|
||||
|
|
|
|||
|
|
@ -845,7 +845,7 @@ static int tracker_deal_get_storage_id(struct fast_task_info *pTask)
|
|||
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
|
||||
char ip_addr[IP_ADDRESS_SIZE];
|
||||
FDFSStorageIdInfo *pFDFSStorageIdInfo;
|
||||
char *storage_id;
|
||||
FDFSStorageId storage_id;
|
||||
int nPkgLen;
|
||||
int id_len;
|
||||
|
||||
|
|
@ -897,21 +897,23 @@ static int tracker_deal_get_storage_id(struct fast_task_info *pTask)
|
|||
return ENOENT;
|
||||
}
|
||||
|
||||
storage_id = pFDFSStorageIdInfo->id;
|
||||
storage_id.ptr = pFDFSStorageIdInfo->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
storage_id = ip_addr;
|
||||
// 当IP地址为IPv6时,其storage_id值为IP地址的short code
|
||||
if (is_ipv6_addr(ip_addr)) {
|
||||
storage_id = fdfs_ip_to_shortcode(ip_addr, FDFS_DEFAULT_STORAGE_ID_LEN);
|
||||
storage_id.ptr = fdfs_ip_to_shortcode(ip_addr,
|
||||
storage_id.holder);
|
||||
} else {
|
||||
storage_id.ptr = ip_addr;
|
||||
}
|
||||
}
|
||||
|
||||
id_len = strlen(storage_id);
|
||||
id_len = strlen(storage_id.ptr);
|
||||
pTask->send.ptr->length = sizeof(TrackerHeader) + id_len;
|
||||
memcpy(pTask->send.ptr->data + sizeof(TrackerHeader), storage_id, id_len);
|
||||
|
||||
memcpy(pTask->send.ptr->data + sizeof(TrackerHeader),
|
||||
storage_id.ptr, id_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1115,10 +1117,13 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask)
|
|||
|
||||
fdfs_multi_ips_to_string(&pIdInfo->ip_addrs,
|
||||
ip_str, sizeof(ip_str));
|
||||
if(strchr(ip_str,':')!=NULL){
|
||||
if (strchr(ip_str, ':') != NULL)
|
||||
{
|
||||
p += sprintf(p, "%s %s [%s]%s\n", pIdInfo->id,
|
||||
pIdInfo->group_name, ip_str, szPortPart);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
p += sprintf(p, "%s %s %s%s\n", pIdInfo->id,
|
||||
pIdInfo->group_name, ip_str, szPortPart);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@
|
|||
#define FDFS_TRUNK_FILE_INFO_LEN 16
|
||||
#define FDFS_MAX_SERVER_ID ((1 << 24) - 1)
|
||||
|
||||
#define FDFS_DEFAULT_STORAGE_ID_LEN 6
|
||||
|
||||
#define FDFS_ID_TYPE_SERVER_ID 1
|
||||
#define FDFS_ID_TYPE_IP_ADDRESS 2
|
||||
|
||||
|
|
@ -473,5 +471,10 @@ typedef struct {
|
|||
bool if_leader; //if leader
|
||||
} TrackerRunningStatus;
|
||||
|
||||
typedef struct {
|
||||
char *ptr;
|
||||
char holder[FDFS_STORAGE_ID_MAX_SIZE];
|
||||
} FDFSStorageId;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue