commit
1809d46020
|
|
@ -16,9 +16,13 @@ base_path = /opt/fastdfs
|
||||||
# and the HOST can be dual IPs or hostnames seperated by comma,
|
# and the HOST can be dual IPs or hostnames seperated by comma,
|
||||||
# the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
|
# the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
|
||||||
# or two different types of inner (intranet) IPs.
|
# or two different types of inner (intranet) IPs.
|
||||||
|
# IPv4:
|
||||||
# for example: 192.168.2.100,122.244.141.46:22122
|
# for example: 192.168.2.100,122.244.141.46:22122
|
||||||
# another eg.: 192.168.1.10,172.17.4.21:22122
|
# another eg.: 192.168.1.10,172.17.4.21:22122
|
||||||
|
#
|
||||||
|
# IPv6:
|
||||||
|
# for example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e,fe80::1ee9:90a8:1351:436c]:22122
|
||||||
|
#
|
||||||
tracker_server = 192.168.0.196:22122
|
tracker_server = 192.168.0.196:22122
|
||||||
tracker_server = 192.168.0.197:22122
|
tracker_server = 192.168.0.197:22122
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ group_name = group1
|
||||||
|
|
||||||
# bind an address of this host
|
# bind an address of this host
|
||||||
# empty for bind all addresses of this host
|
# empty for bind all addresses of this host
|
||||||
|
# IPv4:
|
||||||
|
# for example: 192.168.2.100
|
||||||
|
#
|
||||||
|
# IPv6:
|
||||||
|
# or example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e]
|
||||||
bind_addr =
|
bind_addr =
|
||||||
|
|
||||||
# if bind an address of this host when connect to other servers
|
# if bind an address of this host when connect to other servers
|
||||||
|
|
@ -139,9 +144,13 @@ subdir_count_per_path = 256
|
||||||
# and the HOST can be dual IPs or hostnames seperated by comma,
|
# and the HOST can be dual IPs or hostnames seperated by comma,
|
||||||
# the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
|
# the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
|
||||||
# or two different types of inner (intranet) IPs.
|
# or two different types of inner (intranet) IPs.
|
||||||
|
# IPv4:
|
||||||
# for example: 192.168.2.100,122.244.141.46:22122
|
# for example: 192.168.2.100,122.244.141.46:22122
|
||||||
# another eg.: 192.168.1.10,172.17.4.21:22122
|
# another eg.: 192.168.1.10,172.17.4.21:22122
|
||||||
|
#
|
||||||
|
# IPv6:
|
||||||
|
# for example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e,fe80::1ee9:90a8:1351:436c]:22122
|
||||||
|
#
|
||||||
tracker_server = 192.168.209.121:22122
|
tracker_server = 192.168.209.121:22122
|
||||||
tracker_server = 192.168.209.122:22122
|
tracker_server = 192.168.209.122:22122
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,17 @@
|
||||||
# storage ip or hostname can be dual IPs seperated by comma,
|
# storage ip or hostname can be dual IPs seperated by comma,
|
||||||
# one is an inner (intranet) IP and another is an outer (extranet) IP,
|
# one is an inner (intranet) IP and another is an outer (extranet) IP,
|
||||||
# or two different types of inner (intranet) IPs
|
# or two different types of inner (intranet) IPs
|
||||||
|
# IPv4:
|
||||||
# for example: 192.168.2.100,122.244.141.46
|
# for example: 192.168.2.100,122.244.141.46
|
||||||
# another eg.: 192.168.1.10,172.17.4.21
|
# another eg.: 192.168.1.10,172.17.4.21
|
||||||
#
|
#
|
||||||
|
# IPv6:
|
||||||
|
# or example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e,fe80::1ee9:90a8:1351:436c]
|
||||||
|
# another eg.: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e,fe80::1ee9:90a8:1351:436c]:100002
|
||||||
|
#
|
||||||
# the port is optional. if you run more than one storaged instances
|
# the port is optional. if you run more than one storaged instances
|
||||||
# in a server, you must specified the port to distinguish different instances.
|
# in a server, you must specified the port to distinguish different instances.
|
||||||
|
|
||||||
100001 group1 192.168.0.196
|
100001 group1 192.168.0.196
|
||||||
100002 group1 192.168.0.197
|
100002 group1 192.168.0.197
|
||||||
|
100003 group1 [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e]:100002
|
||||||
|
|
@ -5,6 +5,11 @@ disabled = false
|
||||||
|
|
||||||
# bind an address of this host
|
# bind an address of this host
|
||||||
# empty for bind all addresses of this host
|
# empty for bind all addresses of this host
|
||||||
|
# IPv4:
|
||||||
|
# for example: 192.168.2.100
|
||||||
|
#
|
||||||
|
# IPv6:
|
||||||
|
# or example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e]
|
||||||
bind_addr =
|
bind_addr =
|
||||||
|
|
||||||
# the tracker server port
|
# the tracker server port
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "fastcommon/logger.h"
|
#include "fastcommon/logger.h"
|
||||||
#include "fastcommon/sockopt.h"
|
#include "fastcommon/sockopt.h"
|
||||||
|
#include "fastcommon/local_ip_func.h"
|
||||||
#include "fastcommon/shared_func.h"
|
#include "fastcommon/shared_func.h"
|
||||||
#include "fastcommon/ini_file_reader.h"
|
#include "fastcommon/ini_file_reader.h"
|
||||||
#include "fdht_func.h"
|
#include "fdht_func.h"
|
||||||
|
|
@ -448,7 +449,7 @@ int fdht_load_groups_ex(IniContext *pIniContext, \
|
||||||
pItemEnd = pItemInfo + pServerArray->count;
|
pItemEnd = pItemInfo + pServerArray->count;
|
||||||
for (; pItemInfo<pItemEnd; pItemInfo++)
|
for (; pItemInfo<pItemEnd; pItemInfo++)
|
||||||
{
|
{
|
||||||
if (splitEx(pItemInfo->value, ':', ip_port, 2) != 2)
|
if (parseAddress(pItemInfo->value, ip_port) !=2 )
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"\"%s\" 's value \"%s\" is invalid, "\
|
"\"%s\" 's value \"%s\" is invalid, "\
|
||||||
|
|
@ -468,12 +469,13 @@ int fdht_load_groups_ex(IniContext *pIniContext, \
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(pServerInfo->ip_addr, "127.0.0.1") == 0)
|
if (strcmp(pServerInfo->ip_addr, LOCAL_LOOPBACK_IPv4) == 0 ||
|
||||||
|
strcmp(pServerInfo->ip_addr, LOCAL_LOOPBACK_IPv6) ==0 )
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"group%d: invalid hostname \"%s\", " \
|
"group%d: invalid hostname \"%s\", " \
|
||||||
"ip address can not be 127.0.0.1!", \
|
"ip address can not be %s!", \
|
||||||
__LINE__, group_id, pItemInfo->value);
|
__LINE__, group_id, pItemInfo->value, pServerInfo->ip_addr);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,15 @@ int fdht_connect_server_nb(FDHTServerInfo *pServer, const int connect_timeout)
|
||||||
{
|
{
|
||||||
close(pServer->sock);
|
close(pServer->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通过判断IP地址是IPv4或者IPv6,根据结果进行初始化
|
||||||
|
if (is_ipv6_addr(pServer->ip_addr))
|
||||||
|
{
|
||||||
|
pServer->sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
|
}else{
|
||||||
pServer->sock = socket(AF_INET, SOCK_STREAM, 0);
|
pServer->sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if(pServer->sock < 0)
|
if(pServer->sock < 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
|
|
@ -213,7 +221,15 @@ int fdht_connect_server(FDHTServerInfo *pServer)
|
||||||
{
|
{
|
||||||
close(pServer->sock);
|
close(pServer->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通过判断IP地址是IPv4或者IPv6,根据结果进行初始化
|
||||||
|
if (is_ipv6_addr(pServer->ip_addr))
|
||||||
|
{
|
||||||
|
pServer->sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
|
}else{
|
||||||
pServer->sock = socket(AF_INET, SOCK_STREAM, 0);
|
pServer->sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if(pServer->sock < 0)
|
if(pServer->sock < 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
|
|
|
||||||
|
|
@ -221,14 +221,29 @@ static int storage_get_group_name_from_tracker()
|
||||||
|
|
||||||
static int tracker_get_my_server_id()
|
static int tracker_get_my_server_id()
|
||||||
{
|
{
|
||||||
struct in_addr ip_addr;
|
struct in_addr ipv4_addr;
|
||||||
|
struct in6_addr ipv6_addr;
|
||||||
char ip_str[256];
|
char ip_str[256];
|
||||||
|
bool flag = false;
|
||||||
|
|
||||||
if (inet_pton(AF_INET, g_tracker_client_ip.ips[0].address, &ip_addr) == 1)
|
if (inet_pton(AF_INET, g_tracker_client_ip.ips[0].address, &ipv4_addr) == 1)
|
||||||
{
|
{
|
||||||
g_server_id_in_filename = ip_addr.s_addr;
|
g_server_id_in_filename = ipv4_addr.s_addr;
|
||||||
|
flag = true;
|
||||||
}
|
}
|
||||||
else
|
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));
|
||||||
|
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!flag)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"call inet_pton for ip: %s fail", \
|
"call inet_pton for ip: %s fail", \
|
||||||
|
|
@ -267,11 +282,17 @@ static int tracker_get_my_server_id()
|
||||||
g_tracker_client_ip.ips[0].address);
|
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,
|
fdfs_multi_ips_to_string(&g_tracker_client_ip,
|
||||||
ip_str, sizeof(ip_str));
|
ip_str, sizeof(ip_str));
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"tracker_client_ip: %s, my_server_id_str: %s, "
|
"tracker_client_ip: %s, my_server_id_str: %s, "
|
||||||
"g_server_id_in_filename: %d", __LINE__,
|
"g_server_id_in_filename: %lu", __LINE__,
|
||||||
ip_str, g_my_server_id_str, g_server_id_in_filename);
|
ip_str, g_my_server_id_str, g_server_id_in_filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ FDFSMultiIP g_last_storage_ip = {0, 0}; //the last storage ip address
|
||||||
|
|
||||||
LogContext g_access_log_context = {LOG_INFO, STDERR_FILENO, NULL};
|
LogContext g_access_log_context = {LOG_INFO, STDERR_FILENO, NULL};
|
||||||
|
|
||||||
in_addr_t g_server_id_in_filename = 0;
|
in_addr_64_t g_server_id_in_filename = 0;
|
||||||
bool g_use_access_log = false; //if log to access log
|
bool g_use_access_log = false; //if log to access log
|
||||||
bool g_rotate_access_log = false; //if rotate the access log every day
|
bool g_rotate_access_log = false; //if rotate the access log every day
|
||||||
bool g_compress_old_access_log = false; //if compress the old access log
|
bool g_compress_old_access_log = false; //if compress the old access log
|
||||||
|
|
@ -82,7 +82,7 @@ byte g_file_signature_method = STORAGE_FILE_SIGNATURE_METHOD_HASH;
|
||||||
char g_key_namespace[FDHT_MAX_NAMESPACE_LEN+1] = {0};
|
char g_key_namespace[FDHT_MAX_NAMESPACE_LEN+1] = {0};
|
||||||
int g_namespace_len = 0;
|
int g_namespace_len = 0;
|
||||||
int g_allow_ip_count = 0;
|
int g_allow_ip_count = 0;
|
||||||
in_addr_t *g_allow_ip_addrs = NULL;
|
in_addr_64_t *g_allow_ip_addrs = NULL;
|
||||||
StorageStatusPerTracker *g_my_report_status = NULL; //returned by tracker server
|
StorageStatusPerTracker *g_my_report_status = NULL; //returned by tracker server
|
||||||
|
|
||||||
TimeInfo g_access_log_rotate_time = {0, 0}; //rotate access log time base
|
TimeInfo g_access_log_rotate_time = {0, 0}; //rotate access log time base
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ extern FDFSMultiIP g_last_storage_ip; //the last storage ip address
|
||||||
|
|
||||||
extern LogContext g_access_log_context;
|
extern LogContext g_access_log_context;
|
||||||
|
|
||||||
extern in_addr_t g_server_id_in_filename;
|
extern in_addr_64_t g_server_id_in_filename;
|
||||||
extern bool g_store_slave_file_use_link; //if store slave file use symbol link
|
extern bool g_store_slave_file_use_link; //if store slave file use symbol link
|
||||||
extern bool g_use_storage_id; //identify storage by ID instead of IP address
|
extern bool g_use_storage_id; //identify storage by ID instead of IP address
|
||||||
extern byte g_id_type_in_filename; //id type of the storage server in the filename
|
extern byte g_id_type_in_filename; //id type of the storage server in the filename
|
||||||
|
|
@ -116,7 +116,7 @@ extern char g_key_namespace[FDHT_MAX_NAMESPACE_LEN+1];
|
||||||
extern int g_namespace_len;
|
extern int g_namespace_len;
|
||||||
|
|
||||||
extern int g_allow_ip_count; /* -1 means match any ip address */
|
extern int g_allow_ip_count; /* -1 means match any ip address */
|
||||||
extern in_addr_t *g_allow_ip_addrs; /* sorted array, asc order */
|
extern in_addr_64_t *g_allow_ip_addrs; /* sorted array, asc order */
|
||||||
|
|
||||||
extern StorageStatusPerTracker *g_my_report_status; //returned by tracker server
|
extern StorageStatusPerTracker *g_my_report_status; //returned by tracker server
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1559,12 +1559,12 @@ int storage_set_body_length(struct fast_task_info *pTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sock_accept_done_callback(struct fast_task_info *task,
|
static int sock_accept_done_callback(struct fast_task_info *task,
|
||||||
const in_addr_t client_addr, const bool bInnerPort)
|
const in_addr_64_t client_addr, const bool bInnerPort)
|
||||||
{
|
{
|
||||||
if (g_allow_ip_count >= 0)
|
if (g_allow_ip_count >= 0)
|
||||||
{
|
{
|
||||||
if (bsearch(&client_addr, g_allow_ip_addrs,
|
if (bsearch(&client_addr, g_allow_ip_addrs,
|
||||||
g_allow_ip_count, sizeof(in_addr_t),
|
g_allow_ip_count, sizeof(in_addr_64_t),
|
||||||
cmp_by_ip_addr_t) == NULL)
|
cmp_by_ip_addr_t) == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,7 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
|
||||||
char *group_name;
|
char *group_name;
|
||||||
char *pHost;
|
char *pHost;
|
||||||
char *pPort;
|
char *pPort;
|
||||||
|
char *pTmp;
|
||||||
FDFSStorageIdInfo *pStorageIdInfo;
|
FDFSStorageIdInfo *pStorageIdInfo;
|
||||||
char error_info[256];
|
char error_info[256];
|
||||||
int alloc_bytes;
|
int alloc_bytes;
|
||||||
|
|
@ -429,6 +430,20 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
|
||||||
pHost++;
|
pHost++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理IPv6的前'['括号的问题
|
||||||
|
pTmp = strchr(pHost, '[');
|
||||||
|
if (pTmp != NULL)
|
||||||
|
{
|
||||||
|
pHost++;
|
||||||
|
}
|
||||||
|
|
||||||
|
pPort = strchr(pHost, ']');
|
||||||
|
if(pPort != NULL){
|
||||||
|
*pPort = '\0';
|
||||||
|
pPort++; // ]
|
||||||
|
pPort++; // :
|
||||||
|
pStorageIdInfo->port = atoi(pPort + 1);
|
||||||
|
}else {
|
||||||
pPort = strchr(pHost, ':');
|
pPort = strchr(pHost, ':');
|
||||||
if (pPort != NULL)
|
if (pPort != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -439,6 +454,7 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
|
||||||
{
|
{
|
||||||
pStorageIdInfo->port = 0;
|
pStorageIdInfo->port = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((result=fdfs_parse_multi_ips(pHost, &pStorageIdInfo->ip_addrs,
|
if ((result=fdfs_parse_multi_ips(pHost, &pStorageIdInfo->ip_addrs,
|
||||||
error_info, sizeof(error_info))) != 0)
|
error_info, sizeof(error_info))) != 0)
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include "fastcommon/logger.h"
|
#include "fastcommon/logger.h"
|
||||||
#include "fastcommon/sockopt.h"
|
#include "fastcommon/sockopt.h"
|
||||||
#include "fastcommon/shared_func.h"
|
#include "fastcommon/shared_func.h"
|
||||||
#include "fastcommon/local_ip_func.h"
|
#include "fastcommon/local_ip_func.h"
|
||||||
|
#include "fastcommon/md5.h"
|
||||||
#include "tracker_proto.h"
|
#include "tracker_proto.h"
|
||||||
#include "fdfs_global.h"
|
#include "fdfs_global.h"
|
||||||
#include "fdfs_shared_func.h"
|
#include "fdfs_shared_func.h"
|
||||||
|
|
@ -434,16 +436,40 @@ 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,
|
int fdfs_parse_server_info_ex(char *server_str, const int default_port,
|
||||||
TrackerServerInfo *pServer, const bool resolve)
|
TrackerServerInfo *pServer, const bool resolve)
|
||||||
{
|
{
|
||||||
char *pColon;
|
char *pColon;
|
||||||
|
char *pTmp;
|
||||||
char *hosts[FDFS_MULTI_IP_MAX_COUNT];
|
char *hosts[FDFS_MULTI_IP_MAX_COUNT];
|
||||||
ConnectionInfo *conn;
|
ConnectionInfo *conn;
|
||||||
int port;
|
int port;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(pServer, 0, sizeof(TrackerServerInfo));
|
memset(pServer, 0, sizeof(TrackerServerInfo));
|
||||||
|
|
||||||
|
if((pTmp=strchr(server_str,'[') )!=NULL){
|
||||||
|
deleteChar(server_str,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((pColon=strchr(server_str, ']') ) != NULL){
|
||||||
|
*pColon = '\0';
|
||||||
|
pColon++; // ]
|
||||||
|
port = atoi(pColon + 1);
|
||||||
|
}else {
|
||||||
if ((pColon=strrchr(server_str, ':')) == NULL)
|
if ((pColon=strrchr(server_str, ':')) == NULL)
|
||||||
{
|
{
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
|
|
@ -456,6 +482,7 @@ int fdfs_parse_server_info_ex(char *server_str, const int default_port,
|
||||||
*pColon = '\0';
|
*pColon = '\0';
|
||||||
port = atoi(pColon + 1);
|
port = atoi(pColon + 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conn = pServer->connections;
|
conn = pServer->connections;
|
||||||
pServer->count = splitEx(server_str, ',',
|
pServer->count = splitEx(server_str, ',',
|
||||||
|
|
@ -781,3 +808,40 @@ 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 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;
|
||||||
|
}
|
||||||
|
|
@ -167,6 +167,8 @@ void fdfs_set_server_info(TrackerServerInfo *pServer,
|
||||||
void fdfs_set_server_info_ex(TrackerServerInfo *pServer,
|
void fdfs_set_server_info_ex(TrackerServerInfo *pServer,
|
||||||
const FDFSMultiIP *ip_addrs, const int port);
|
const FDFSMultiIP *ip_addrs, const int port);
|
||||||
|
|
||||||
|
char* fdfs_ip_to_shortcode(const char* ipAddr, int shortCodeLength);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ FDFSStorageReservedSpace g_storage_reserved_space = { \
|
||||||
TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB};
|
TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB};
|
||||||
|
|
||||||
int g_allow_ip_count = 0;
|
int g_allow_ip_count = 0;
|
||||||
in_addr_t *g_allow_ip_addrs = NULL;
|
in_addr_64_t *g_allow_ip_addrs = NULL;
|
||||||
|
|
||||||
struct base64_context g_base64_context;
|
struct base64_context g_base64_context;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ extern FDFSStorageReservedSpace g_storage_reserved_space;
|
||||||
extern int g_check_active_interval; //check storage server alive every interval seconds
|
extern int g_check_active_interval; //check storage server alive every interval seconds
|
||||||
|
|
||||||
extern int g_allow_ip_count; /* -1 means match any ip address */
|
extern int g_allow_ip_count; /* -1 means match any ip address */
|
||||||
extern in_addr_t *g_allow_ip_addrs; /* sorted array, asc order */
|
extern in_addr_64_t *g_allow_ip_addrs; /* sorted array, asc order */
|
||||||
extern struct base64_context g_base64_context;
|
extern struct base64_context g_base64_context;
|
||||||
|
|
||||||
extern bool g_storage_ip_changed_auto_adjust;
|
extern bool g_storage_ip_changed_auto_adjust;
|
||||||
|
|
|
||||||
|
|
@ -3182,6 +3182,10 @@ static FDFSStorageDetail *tracker_mem_get_active_http_server_by_ip( \
|
||||||
if (!g_use_storage_id)
|
if (!g_use_storage_id)
|
||||||
{
|
{
|
||||||
strcpy(target_storage.id, ip_addr);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -3255,6 +3259,10 @@ FDFSStorageDetail *tracker_mem_get_storage_by_ip(FDFSGroupInfo *pGroup, \
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
storage_id = ip_addr;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tracker_mem_get_storage(pGroup, storage_id);
|
return tracker_mem_get_storage(pGroup, storage_id);
|
||||||
|
|
@ -3719,6 +3727,10 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
storage_id = ip_addr;
|
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 (bNeedLock && (result=pthread_mutex_lock(&mem_thread_lock)) != 0)
|
if (bNeedLock && (result=pthread_mutex_lock(&mem_thread_lock)) != 0)
|
||||||
|
|
@ -4496,6 +4508,11 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
||||||
{
|
{
|
||||||
pStorageIdInfo = NULL;
|
pStorageIdInfo = NULL;
|
||||||
storage_id = ip_addr;
|
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 (pClientInfo->pGroup->storage_port == 0)
|
if (pClientInfo->pGroup->storage_port == 0)
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ static void task_finish_clean_up(struct fast_task_info *pTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sock_accept_done_callback(struct fast_task_info *task,
|
static int sock_accept_done_callback(struct fast_task_info *task,
|
||||||
const in_addr_t client_addr, const bool bInnerPort)
|
const in_addr_64_t client_addr, const bool bInnerPort)
|
||||||
{
|
{
|
||||||
if (g_allow_ip_count >= 0)
|
if (g_allow_ip_count >= 0)
|
||||||
{
|
{
|
||||||
if (bsearch(&client_addr, g_allow_ip_addrs,
|
if (bsearch(&client_addr, g_allow_ip_addrs,
|
||||||
g_allow_ip_count, sizeof(in_addr_t),
|
g_allow_ip_count, sizeof(in_addr_64_t),
|
||||||
cmp_by_ip_addr_t) == NULL)
|
cmp_by_ip_addr_t) == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
|
@ -902,6 +902,10 @@ static int tracker_deal_get_storage_id(struct fast_task_info *pTask)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
storage_id = ip_addr;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id_len = strlen(storage_id);
|
id_len = strlen(storage_id);
|
||||||
|
|
@ -1111,9 +1115,14 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask)
|
||||||
|
|
||||||
fdfs_multi_ips_to_string(&pIdInfo->ip_addrs,
|
fdfs_multi_ips_to_string(&pIdInfo->ip_addrs,
|
||||||
ip_str, sizeof(ip_str));
|
ip_str, sizeof(ip_str));
|
||||||
|
if(strchr(ip_str,':')!=NULL){
|
||||||
|
p += sprintf(p, "%s %s [%s]%s\n", pIdInfo->id,
|
||||||
|
pIdInfo->group_name, ip_str, szPortPart);
|
||||||
|
}else{
|
||||||
p += sprintf(p, "%s %s %s%s\n", pIdInfo->id,
|
p += sprintf(p, "%s %s %s%s\n", pIdInfo->id,
|
||||||
pIdInfo->group_name, ip_str, szPortPart);
|
pIdInfo->group_name, ip_str, szPortPart);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int2buff((int)(pIdInfo - pIdsStart), (char *)pCurrentCount);
|
int2buff((int)(pIdInfo - pIdsStart), (char *)pCurrentCount);
|
||||||
pTask->send.ptr->length = p - pTask->send.ptr->data;
|
pTask->send.ptr->length = p - pTask->send.ptr->data;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@
|
||||||
#define FDFS_TRUNK_FILE_INFO_LEN 16
|
#define FDFS_TRUNK_FILE_INFO_LEN 16
|
||||||
#define FDFS_MAX_SERVER_ID ((1 << 24) - 1)
|
#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_SERVER_ID 1
|
||||||
#define FDFS_ID_TYPE_IP_ADDRESS 2
|
#define FDFS_ID_TYPE_IP_ADDRESS 2
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue