if (bind(udpPollSock.fd, (struct sockaddr *)&myAddr, socklen) < 0)
perror("dhtInit():bind()");
- if (seed == 0){
+ if (seed == 0) {
dhtLog("I am the leader\n");
leader = myHostData.ipAddr;
setState(LEAD_NORMAL1_STATE);
toAddr.sin_family = AF_INET;
toAddr.sin_port = htons(UDP_PORT);
- while (status != OPERATION_OK){
+ while (status != OPERATION_OK) {
pthread_mutex_lock(&stateMutex);
while (!(state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
|| state == LEAD_NORMAL2_STATE || state == REBUILD4_STATE
toAddr.sin_addr.s_addr = htonl(getKeyOwner(key));
pthread_mutex_unlock(&stateMutex);
- if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
+ if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("dhtInsert():socket()");
return -1;
}
write4(&outBuffer[1], key);
write4(&outBuffer[5], val);
- for (i = 0; i < INSERT_RETRIES; i++){
+ for (i = 0; i < INSERT_RETRIES; i++) {
if (sendto(pollsock.fd, outBuffer, 9, 0, (struct sockaddr *)&toAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("dhtInsert():sendto()");
break;
}
retval = poll(&pollsock, 1, INSERT_TIMEOUT_MS);
- if (retval < 0){
+ if (retval < 0) {
perror("dhtInsert():poll()");
break;
}
- if (retval > 0){
+ if (retval > 0) {
bytesRcvd = recvfrom(pollsock.fd, inBuffer, 2, 0,
(struct sockaddr *)&fromAddr, &socklen);
if (fromAddr.sin_addr.s_addr == toAddr.sin_addr.s_addr
&& fromAddr.sin_port == toAddr.sin_port
- && bytesRcvd == 2 && inBuffer[0] == INSERT_RES){
+ && bytesRcvd == 2 && inBuffer[0] == INSERT_RES) {
status = inBuffer[1]; //status from remote host
break;
}
}
}
- if (status != OPERATION_OK){
+ if (status != OPERATION_OK) {
pthread_mutex_lock(&stateMutex);
setState(REBUILD0_STATE);
outBuffer[0] = REBUILD_REQ;
int i;
status = 0;
- for (i = 0; i < numKeys; i++){
+ for (i = 0; i < numKeys; i++) {
if (dhtInsert(keys[i], vals[i]) != 0)
status = -1;
}
toAddr.sin_family = AF_INET;
toAddr.sin_port = htons(UDP_PORT);
- while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
while (!(state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
|| state == LEAD_NORMAL2_STATE))
toAddr.sin_addr.s_addr = htonl(getKeyOwner(key));
pthread_mutex_unlock(&stateMutex);
- if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
+ if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("dhtRemove():socket()");
return -1;
}
outBuffer[0] = REMOVE_CMD;
write4(&outBuffer[1], key);
- for (i = 0; i < REMOVE_RETRIES; i++){
+ for (i = 0; i < REMOVE_RETRIES; i++) {
if (sendto(pollsock.fd, outBuffer, 5, 0, (struct sockaddr *)&toAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("dhtRemove():sendto()");
break;
}
retval = poll(&pollsock, 1, REMOVE_TIMEOUT_MS);
- if (retval < 0){
+ if (retval < 0) {
perror("dhtRemove():poll()");
break;
}
- if (retval > 0){
+ if (retval > 0) {
bytesRcvd = recvfrom(pollsock.fd, inBuffer, 2, 0,
(struct sockaddr *)&fromAddr, &socklen);
if (fromAddr.sin_addr.s_addr == toAddr.sin_addr.s_addr
&& fromAddr.sin_port == toAddr.sin_port
- && bytesRcvd == 2 && inBuffer[0] == REMOVE_RES){
+ && bytesRcvd == 2 && inBuffer[0] == REMOVE_RES) {
status = inBuffer[1]; //status from remote host
break;
}
}
}
- if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
setState(REBUILD0_STATE);
outBuffer[0] = REBUILD_REQ;
int i;
status = 0;
- for (i = 0; i < numKeys; i++){
+ for (i = 0; i < numKeys; i++) {
if (dhtRemove(keys[i]) != 0)
status = -1;
}
toAddr.sin_family = AF_INET;
toAddr.sin_port = htons(UDP_PORT);
- while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ while (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
while (numBlocks == 0)
pthread_cond_wait(&stateCond, &stateMutex);
toAddr.sin_addr.s_addr = htonl(getKeyOwner(key));
pthread_mutex_unlock(&stateMutex);
- if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
+ if ((pollsock.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("dhtSearch():socket()");
return -1;
}
outBuffer[0] = SEARCH_CMD;
write4(&outBuffer[1], key);
- for (i = 0; i < SEARCH_RETRIES; i++){
+ for (i = 0; i < SEARCH_RETRIES; i++) {
if (sendto(pollsock.fd, outBuffer, 5, 0, (struct sockaddr *)&toAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("dhtSearch():sendto()");
break;
}
retval = poll(&pollsock, 1, SEARCH_TIMEOUT_MS);
- if (retval < 0){
+ if (retval < 0) {
perror("dhtSearch():poll()");
break;
}
- if (retval > 0){
+ if (retval > 0) {
bytesRcvd = recvfrom(pollsock.fd, inBuffer, 6, 0,
(struct sockaddr *)&fromAddr, &socklen);
if (fromAddr.sin_addr.s_addr == toAddr.sin_addr.s_addr
&& fromAddr.sin_port == toAddr.sin_port
- && bytesRcvd == 6 && inBuffer[0] == SEARCH_RES){
+ && bytesRcvd == 6 && inBuffer[0] == SEARCH_RES) {
status = inBuffer[1]; //status from remote host
*val = read4(&inBuffer[2]);
break;
}
}
}
- if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)){
+ if (!(status == OPERATION_OK || status == KEY_NOT_FOUND)) {
pthread_mutex_lock(&stateMutex);
setState(REBUILD0_STATE);
outBuffer[0] = REBUILD_REQ;
int dhtSearchMult(unsigned int numKeys, unsigned int *keys, unsigned int *vals) {
int i;
int status = 0;
- for (i = 0; i < numKeys; i++){
+ for (i = 0; i < numKeys; i++) {
if (dhtSearch(keys[i], &vals[i]) != 0)
status = -1;
}
if (size < 1)
return 1;
- switch (msg[0]){
+ switch (msg[0]) {
case WHO_IS_LEADER_CMD:
case LEAVE_REQ:
case LEAVE_RES:
memset(&interfaceInfo, 0, sizeof(struct ifreq));
- if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
+ if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("getMyIpAddr():socket()");
return 1;
}
strcpy(interfaceInfo.ifr_name, interfaceStr);
myAddr->sin_family = AF_INET;
- if(ioctl(sock, SIOCGIFADDR, &interfaceInfo) != 0){
+ if(ioctl(sock, SIOCGIFADDR, &interfaceInfo) != 0) {
perror("getMyIpAddr():ioctl()");
return 1;
}
peerAddr.sin_addr.s_addr = htonl(destIp);
peerAddr.sin_port = htons(UDP_PORT);
- if (size >= 1){
+ if (size >= 1) {
if (msg[0] < NUM_MSG_TYPES)
dhtLog("udpSend(): sending %s to %s, %d bytes\n", msg_types[msg[0]],
inet_ntoa(peerAddr.sin_addr), size);
}
if (sendto(udpPollSock.fd, (void *)msg, size, 0, (struct sockaddr *)&peerAddr,
- socklen) < 0){
+ socklen) < 0) {
perror("udpSend():sendto()");
return -1;
}
int udpSendAll(unsigned char *msg, unsigned int size) {
int i;
int status = 0;
- for (i = 0; i < numHosts; i++){
- if ((hostReplied[i] == 0) && (hostArray[i].ipAddr != myHostData.ipAddr)){
+ for (i = 0; i < numHosts; i++) {
+ if ((hostReplied[i] == 0) && (hostArray[i].ipAddr != myHostData.ipAddr)) {
if (udpSend(msg, size, hostArray[i].ipAddr) != 0)
status = -1;
}
gettimeofday(&now, NULL);
- if (newState >= NUM_STATES){
+ if (newState >= NUM_STATES) {
dhtLog("setState(): ERROR: invalid state %d\n", newState);
} else
{
if (timeout_vals[newState].tv_sec == 0
- && timeout_vals[newState].tv_usec == 0){ //no timer
+ && timeout_vals[newState].tv_usec == 0) { //no timer
timerSet = 0;
} else
{
if (i == -1)
return -1;
- for (j = 0; j < numBlocks; j++){
+ for (j = 0; j < numBlocks; j++) {
if (blockOwnerArray[j] == i)
blockOwnerArray[j] = 0; //TODO: is this what I want to have happen?
else if (blockOwnerArray[j] > i)
blockOwnerArray[j]--;
}
- for (; i < numHosts - 1; i++){
+ for (; i < numHosts - 1; i++) {
hostArray[i] = hostArray[i+1];
hostReplied[i] = hostReplied[i+1];
}
void removeUnresponsiveHosts() {
int i;
- for (i = 0; i < numHosts; i++){
+ for (i = 0; i < numHosts; i++) {
if (!hostReplied[i] && hostArray[i].ipAddr != myHostData.ipAddr)
removeHost(hostArray[i].ipAddr);
}
int i;
int j;
- for (i = 0; i < numHosts; i++){
- if (hostArray[i].ipAddr == newHost.ipAddr){
+ for (i = 0; i < numHosts; i++) {
+ if (hostArray[i].ipAddr == newHost.ipAddr) {
hostArray[i] = newHost;
hostReplied[i] = 0;
return 0;
} else if (hostArray[i].ipAddr > newHost.ipAddr) {
- if (numHosts == hostArraySize){
+ if (numHosts == hostArraySize) {
newHostArray = calloc(2 * hostArraySize, sizeof(struct hostData));
newHostReplied = calloc(2 * hostArraySize, sizeof(unsigned char));
memcpy(newHostArray, hostArray, (i * sizeof(struct hostData)));
hostArraySize = 2 * hostArraySize;
} else
{
- for (j = numHosts; j > i; j--){
+ for (j = numHosts; j > i; j--) {
hostArray[j] = hostArray[j-1];
hostReplied[j] = hostReplied[j-1];
}
hostArray[i] = newHost;
hostReplied[i] = 0;
}
- for(j = 0; j < numBlocks; j++){
+ for(j = 0; j < numBlocks; j++) {
if (blockOwnerArray[j] >= i)
blockOwnerArray[j]++;
}
}
//nothing greater, add to end
- if (numHosts == hostArraySize){
+ if (numHosts == hostArraySize) {
newHostArray = calloc(2 * hostArraySize, sizeof(struct hostData));
newHostReplied = calloc(2 * hostArraySize, sizeof(unsigned char));
memcpy(newHostArray, hostArray, (numHosts * sizeof(struct hostData)));
void makeAssignments() {
int i;
- if (numBlocks < numHosts){
+ if (numBlocks < numHosts) {
free(blockOwnerArray);
while (numBlocks < numHosts)
numBlocks *= 2;
struct in_addr tmpAddr;
fprintf(logfile, "numHosts = %d\n", numHosts);
- for (i = 0; i < numHosts; i++){
+ for (i = 0; i < numHosts; i++) {
tmpAddr.s_addr = htonl(hostArray[i].ipAddr);
fprintf(logfile, "%d) %s, %d\n", i, inet_ntoa(tmpAddr),
hostArray[i].maxKeyCapacity);
va_start(args, format);
// if (fprintf(logfile, "%d.%06d:", now.tv_sec, now.tv_usec) < 0)
// { perror("dhtLog():fprintf()"); }
- if (vfprintf(logfile, format, args) < 0){
+ if (vfprintf(logfile, format, args) < 0) {
perror("dhtLog():vfprintf()");
}
- if (fflush(logfile) == EOF){
+ if (fflush(logfile) == EOF) {
perror("dhtLog():fflush()");
}
va_end(args);
dhtLog("udpListen(): linstening on port %d...\n", UDP_PORT);
- while (1){
+ while (1) {
pollret = poll(&udpPollSock, 1, TIMEOUT_PERIOD);
pthread_mutex_lock(&stateMutex);
oldState = state;
- if (pollret < 0){
+ if (pollret < 0) {
perror("udpListen():poll()");
} else if (pollret > 0) {
bytesRcvd = recvfrom(udpPollSock.fd, inBuffer, MAX_MSG_SIZE, 0,
(struct sockaddr *)&peerAddr, &socklen);
- if (bytesRcvd < 1){
+ if (bytesRcvd < 1) {
dhtLog("udpListen(): ERROR: bytesRcvd = %d\n", bytesRcvd);
} else if (inBuffer[0] >= NUM_MSG_TYPES) {
dhtLog("udpListen(): ERROR: unknown msg type = %d\n", inBuffer[0]);
dhtLog(" %x", inBuffer[i]);
dhtLog("\n");
peerIp = ntohl(peerAddr.sin_addr.s_addr);
- if (peerIp == seed && inBuffer[0] == WHO_IS_LEADER_RES){
+ if (peerIp == seed && inBuffer[0] == WHO_IS_LEADER_RES) {
tmpHost.ipAddr = peerIp;
tmpHost.maxKeyCapacity = 0;
addHost(tmpHost);
leader = read4(&inBuffer[1]);
tmpAddr.s_addr = htonl(leader);
dhtLog("leader = %s\n", inet_ntoa(tmpAddr));
- if (leader != 0){
+ if (leader != 0) {
setState(INIT2_STATE);
outBuffer[0] = JOIN_REQ;
write4(&outBuffer[1], myHostData.maxKeyCapacity);
dhtLog(" %x", inBuffer[i]);
dhtLog("\n");
peerIp = ntohl(peerAddr.sin_addr.s_addr);
- switch (inBuffer[0]){
+ switch (inBuffer[0]) {
case INSERT_CMD:
if (state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
|| state == LEAD_NORMAL2_STATE || state == REBUILD4_STATE
- || state == REBUILD5_STATE || state == LEAD_REBUILD3_STATE){
+ || state == REBUILD5_STATE || state == LEAD_REBUILD3_STATE) {
tmpKey = read4(&inBuffer[1]);
tmpVal = read4(&inBuffer[5]);
outBuffer[0] = INSERT_RES;
- if (getKeyOwner(tmpKey) == myHostData.ipAddr){
+ if (getKeyOwner(tmpKey) == myHostData.ipAddr) {
if (chashInsert(myHashTable, tmpKey, (void *)tmpVal) == 0)
outBuffer[1] = OPERATION_OK;
else
case REMOVE_CMD:
if (state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
- || state == LEAD_NORMAL2_STATE){
+ || state == LEAD_NORMAL2_STATE) {
tmpKey = read4(&inBuffer[1]);
outBuffer[0] = REMOVE_RES;
- if (getKeyOwner(tmpKey) == myHostData.ipAddr){
+ if (getKeyOwner(tmpKey) == myHostData.ipAddr) {
if (chashRemove(myHashTable, tmpKey) == 0)
outBuffer[1] = OPERATION_OK;
else
case SEARCH_CMD:
if (state == NORMAL_STATE || state == LEAD_NORMAL1_STATE
- || state == LEAD_NORMAL2_STATE){
+ || state == LEAD_NORMAL2_STATE) {
tmpKey = read4(&inBuffer[1]);
outBuffer[0] = SEARCH_RES;
- if (getKeyOwner(tmpKey) == myHostData.ipAddr){
- if ((tmpVal = (unsigned int)chashSearch(myHashTable, tmpKey)) != 0){
+ if (getKeyOwner(tmpKey) == myHostData.ipAddr) {
+ if ((tmpVal = (unsigned int)chashSearch(myHashTable, tmpKey)) != 0) {
outBuffer[1] = OPERATION_OK;
write4(&outBuffer[2], tmpVal);
} else
break;
case JOIN_REQ:
- if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE){
+ if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE) {
tmpHost.ipAddr = peerIp;
tmpHost.maxKeyCapacity = read4(&inBuffer[1]);
addHost(tmpHost);
outBuffer[0] = JOIN_RES;
outBuffer[1] = 0; //status, success
udpSend(outBuffer, 2, peerIp);
- if (allReplied()){
+ if (allReplied()) {
makeAssignments();
setState(LEAD_REBUILD2_STATE);
outBuffer[0] = DHT_UPDATE_CMD;
break;
case JOIN_RES:
- if (state == REBUILD1_STATE){
+ if (state == REBUILD1_STATE) {
setState(REBUILD2_STATE);
} else if (state == INIT2_STATE) {
setState(NORMAL_STATE);
break;
case LEAVE_REQ:
- if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE){ //TODO: make this graceful, instead of just rebuilding
+ if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE) { //TODO: make this graceful, instead of just rebuilding
removeHost(peerIp);
if (state != LEAD_NORMAL2_STATE)
setState(LEAD_NORMAL2_STATE);
break;
case DHT_UPDATE_CMD:
- if (state == REBUILD2_STATE && peerIp == leader){
+ if (state == REBUILD2_STATE && peerIp == leader) {
free(hostArray);
free(blockOwnerArray);
numHosts = read2(&inBuffer[1]);
break;
case DHT_UPDATE_RES:
- if (state == LEAD_REBUILD2_STATE){
+ if (state == LEAD_REBUILD2_STATE) {
checkReplied(peerIp);
- if (allReplied()){
+ if (allReplied()) {
setState(LEAD_REBUILD3_STATE);
outBuffer[0] = FILL_DHT_CMD;
udpSendAll(outBuffer, 1);
case ELECT_LEADER_CMD:
tmpUInt = read4(&inBuffer[1]);
if ((state == ELECT1_STATE || state == ELECT2_STATE)
- && tmpUInt >= electionOriginator){ //already participating in a higher-priority election
+ && tmpUInt >= electionOriginator) { //already participating in a higher-priority election
outBuffer[0] = ELECT_LEADER_RES;
outBuffer[1] = 0xFF;
udpSend(outBuffer, 2, peerIp);
//don't bother forwarding the message to originator or parent
checkReplied(electionOriginator);
checkReplied(electionParent);
- if (allReplied()){ //in case that is everybody I know of
+ if (allReplied()) { //in case that is everybody I know of
setState(ELECT2_STATE);
outBuffer[0] = ELECT_LEADER_RES;
outBuffer[1] = 0;
break;
case ELECT_LEADER_RES:
- if (state == ELECT1_STATE){
+ if (state == ELECT1_STATE) {
checkReplied(peerIp);
- if (inBuffer[1] != 0xFF){
+ if (inBuffer[1] != 0xFF) {
tmpUShort = read2(&inBuffer[2]);
hostDataPtr = (struct hostData *)&inBuffer[4];
for (i = 0; i < tmpUShort; i++)
addHost(hostDataPtr[i]);
writeHostList();
}
- if (allReplied()){
+ if (allReplied()) {
setState(ELECT2_STATE);
- if (electionOriginator == myHostData.ipAddr){
+ if (electionOriginator == myHostData.ipAddr) {
leader = hostArray[0].ipAddr;
- if (leader == myHostData.ipAddr){ //I am the leader
+ if (leader == myHostData.ipAddr) { //I am the leader
dhtLog("I am the leader!\n");
setState(LEAD_REBUILD1_STATE);
outBuffer[0] = REBUILD_CMD;
break;
case CONGRATS_CMD:
- if (state == ELECT2_STATE){ //I am the leader
+ if (state == ELECT2_STATE) { //I am the leader
leader = myHostData.ipAddr;
dhtLog("I am the leader!\n");
tmpUShort = read2(&inBuffer[1]);
break;
case REBUILD_REQ:
- if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE){
+ if (state == LEAD_NORMAL1_STATE || state == LEAD_NORMAL2_STATE) {
setState(LEAD_REBUILD1_STATE);
outBuffer[0] = REBUILD_CMD;
udpSendAll(outBuffer, 1);
break;
case FILL_DHT_CMD:
- if (state == REBUILD3_STATE && peerIp == leader){
+ if (state == REBUILD3_STATE && peerIp == leader) {
setState(REBUILD4_STATE);
if (fillStatus != 0)
dhtLog("udpListen(): ERROR: fillTask already running\n");
break;
case FILL_DHT_RES:
- if (state == LEAD_REBUILD3_STATE){
+ if (state == LEAD_REBUILD3_STATE) {
checkReplied(peerIp);
- if (allReplied() && fillStatus == 2){
+ if (allReplied() && fillStatus == 2) {
fillStatus = 0;
setState(LEAD_REBUILD4_STATE);
outBuffer[0] = RESUME_NORMAL_CMD;
break;
case RESUME_NORMAL_CMD:
- if (state == REBUILD5_STATE && peerIp == leader){
+ if (state == REBUILD5_STATE && peerIp == leader) {
setState(NORMAL_STATE);
outBuffer[0] = RESUME_NORMAL_RES;
udpSend(outBuffer, 1, leader);
break;
case RESUME_NORMAL_RES:
- if (state == LEAD_REBUILD4_STATE){
+ if (state == LEAD_REBUILD4_STATE) {
checkReplied(peerIp);
- if (allReplied()){
+ if (allReplied()) {
setState(LEAD_NORMAL1_STATE);
}
}
}
}
}
- if (state == REBUILD4_STATE){
- switch (fillStatus){
+ if (state == REBUILD4_STATE) {
+ switch (fillStatus) {
case 0: dhtLog("udpListen(): ERROR: fillStatus=0 in REBUILD4_STATE\n");
break;
break;
}
}
- if (state == LEAD_REBUILD3_STATE){
- switch (fillStatus){
+ if (state == LEAD_REBUILD3_STATE) {
+ switch (fillStatus) {
case 0: dhtLog("udpListen(): ERROR: fillStatus=0 in LEAD_REBUILD3_STATE\n");
break;
break;
case 2: //I'm done, now is everybody else also done?
- if (allReplied()){
+ if (allReplied()) {
fillStatus = 0;
setState(LEAD_REBUILD4_STATE);
outBuffer[0] = RESUME_NORMAL_CMD;
break;
}
}
- if (timerSet){
+ if (timerSet) {
gettimeofday(&now, NULL);
- if (timercmp(&now, &timer, >)){
- if (timeoutCntr < retry_vals[state]){
+ if (timercmp(&now, &timer, >)) {
+ if (timeoutCntr < retry_vals[state]) {
timeoutCntr++;
timeradd(&now, &timeout_vals[state], &timer);
dhtLog("udpListen(): retry: %d\n", timeoutCntr);
- switch (state){
+ switch (state) {
case INIT1_STATE:
outBuffer[0] = WHO_IS_LEADER_CMD;
udpSend(outBuffer, 1, seed);
break;
case ELECT2_STATE:
- if (electionOriginator == myHostData.ipAddr){ //retry notify leader
+ if (electionOriginator == myHostData.ipAddr) { //retry notify leader
outBuffer[0] = CONGRATS_CMD;
write2(&outBuffer[1], numHosts);
memcpy(&outBuffer[3], hostArray, sizeof(struct hostData)
{
dhtLog("udpListen(): timed out in state %s after %d retries\n",
state_names[state], timeoutCntr);
- switch (state){
+ switch (state) {
case INIT1_STATE:
setState(EXIT2_STATE);
break;
dhtLog("after\n");
writeHostList();
setState(ELECT2_STATE);
- if (electionOriginator == myHostData.ipAddr){
+ if (electionOriginator == myHostData.ipAddr) {
leader = hostArray[0].ipAddr;
- if (leader == myHostData.ipAddr){ //I am the leader
+ if (leader == myHostData.ipAddr) { //I am the leader
dhtLog("I am the leader!\n");
setState(LEAD_REBUILD1_STATE);
outBuffer[0] = REBUILD_CMD;