| 1 | /* |
| 2 | * node.c |
| 3 | * |
| 4 | * Copyright (C) 2017 Aerospike, Inc. |
| 5 | * |
| 6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
| 7 | * license agreements. |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU Affero General Public License as published by the Free |
| 11 | * Software Foundation, either version 3 of the License, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
| 21 | */ |
| 22 | |
| 23 | #include "node.h" |
| 24 | |
| 25 | #include <errno.h> |
| 26 | #include <stdint.h> |
| 27 | #include <unistd.h> |
| 28 | |
| 29 | #include "citrusleaf/alloc.h" |
| 30 | |
| 31 | #include "fault.h" |
| 32 | |
| 33 | |
| 34 | uint32_t |
| 35 | cf_nodeid_shash_fn(const void *key) |
| 36 | { |
| 37 | cf_node id = *(const cf_node *)key; |
| 38 | |
| 39 | return (uint32_t)(id >> 32) | (uint32_t)id; |
| 40 | } |
| 41 | |
| 42 | uint32_t |
| 43 | cf_nodeid_rchash_fn(const void *key, uint32_t key_size) |
| 44 | { |
| 45 | (void)key_size; |
| 46 | |
| 47 | return cf_nodeid_shash_fn(key); |
| 48 | } |
| 49 | |
| 50 | char * |
| 51 | cf_node_name() |
| 52 | { |
| 53 | char buffer[1024]; |
| 54 | int res = gethostname(buffer, sizeof(buffer)); |
| 55 | |
| 56 | if (res == (int)sizeof(buffer) || (res < 0 && errno == ENAMETOOLONG)) { |
| 57 | cf_crash(CF_MISC, "host name too long" ); |
| 58 | } |
| 59 | |
| 60 | if (res < 0) { |
| 61 | cf_warning(CF_MISC, "error while determining host name: %d (%s)" , |
| 62 | errno, cf_strerror(errno)); |
| 63 | buffer[0] = 0; |
| 64 | } |
| 65 | |
| 66 | return cf_strdup(buffer); |
| 67 | } |
| 68 | |