Commit c552afd9 authored by Scott Vokes's avatar Scott Vokes
Browse files

Add vendor/json-c/, update Makefile, start on service discovery tool.

The service discovery tool still needs multicast enabled.
parent d48e3329
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -16,3 +16,6 @@
[submodule "vendor/FlameGraph"]
	path = vendor/FlameGraph
	url = https://github.com/brendangregg/FlameGraph.git
[submodule "vendor/json-c"]
	path = vendor/json-c
	url = https://github.com/json-c/json-c
+50 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ SYSTEM_TEST_HOST ?= \"localhost\"
WARN = -Wall -Wextra -Werror -Wstrict-prototypes -Wcast-align -pedantic -Wno-missing-field-initializers -Werror=strict-prototypes
CDEFS += -D_POSIX_C_SOURCE=199309L -D_C99_SOURCE=1 -DSYSTEM_TEST_HOST=${SYSTEM_TEST_HOST}
CFLAGS += -std=c99 -fPIC -g $(WARN) $(CDEFS) $(OPTIMIZE)
LDFLAGS += -lm -L${OPENSSL_PATH}/lib -lcrypto -lssl -lpthread
LDFLAGS += -lm -L${OPENSSL_PATH}/lib -lcrypto -lssl -lpthread -ljson-c

#===============================================================================
# Kinetic-C Library Build Support
@@ -38,6 +38,7 @@ LIB_DIR = ./src/lib
VENDOR = ./vendor
PROTOBUFC = $(VENDOR)/protobuf-c
SOCKET99 = $(VENDOR)/socket99
JSONC = $(VENDOR)/json-c
VERSION_FILE = ./config/VERSION
VERSION = ${shell head -n1 $(VERSION_FILE)}
THREADPOOL_PATH = ${LIB_DIR}/threadpool
@@ -46,7 +47,7 @@ BUS_PATH = ${LIB_DIR}/bus
KINETIC_LIB_NAME = $(PROJECT).$(VERSION)
KINETIC_LIB = $(BIN_DIR)/lib$(KINETIC_LIB_NAME).a
LIB_INCS = -I$(LIB_DIR) -I$(PUB_INC) -I$(PROTOBUFC) -I$(SOCKET99) -I$(VENDOR) \
	-I$(THREADPOOL_PATH) -I$(BUS_PATH) -I${OPENSSL_PATH}/include
	-I$(JSONC) -I$(THREADPOOL_PATH) -I$(BUS_PATH) -I${OPENSSL_PATH}/include

C_SRC=${LIB_DIR}/*.[ch] $(SOCKET99)/socket99.[ch] $(PROTOBUFC)/protobuf-c/protobuf-c.[ch]

@@ -95,7 +96,7 @@ makedirs:
all: default test system_tests test_internals run examples

clean: makedirs update_git_submodules
	rm -rf ./bin/*.a ./bin/*.so ./bin/kinetic-c-util
	rm -rf ./bin/*.a ./bin/*.so ./bin/kinetic-c-util $(DISCOVERY_UTIL_EXEC)
	rm -rf ./bin/**/*
	rm -f $(OUT_DIR)/*.o $(OUT_DIR)/*.a *.core *.log
	bundle exec rake clobber
@@ -103,6 +104,7 @@ clean: makedirs update_git_submodules
	cd ${SOCKET99} && make clean
	cd ${LIB_DIR}/threadpool && make clean
	cd ${LIB_DIR}/bus && make clean
	cd ${JSONC} && make clean

update_git_submodules:
	git submodule update --init
@@ -151,6 +153,24 @@ ci: uninstall all stop_simulator test_internals install
	@echo


#-------------------------------------------------------------------------------
# json-c
#-------------------------------------------------------------------------------

json: ${OUT_DIR}/libjson-c.a

${JSONC}/Makefile:
	cd ${JSONC} && \
	sh autogen.sh && \
	./configure

${JSONC}/.libs/libjson-c.a: ${JSONC}/Makefile
	cd ${JSONC} && \
	make libjson-c.la

${OUT_DIR}/libjson-c.a: ${JSONC}/.libs/libjson-c.a
	cp ${JSONC}/.libs/libjson-c.a ${OUT_DIR}/libjson-c.a

#-------------------------------------------------------------------------------
# Test Support
#-------------------------------------------------------------------------------
@@ -338,6 +358,33 @@ utility: $(UTIL_EXEC)
build: $(KINETIC_LIB) $(KINETIC_SO_DEV) utility


#===============================================================================
# Service Discovery Utility Build Support
#===============================================================================

DISCOVERY_UTILITY = kinetic-c-discovery
DISCOVERY_UTIL_DIR = $(UTIL_DIR)
DISCOVERY_UTIL_EXEC = $(BIN_DIR)/$(DISCOVERY_UTILITY)
DISCOVERY_UTIL_OBJ = $(OUT_DIR)/discovery.o $(OUT_DIR)/socket99.o
DISCOVERY_UTIL_LDFLAGS +=  -lm -lssl $(KINETIC_LIB) -L${OUT_DIR} -lcrypto -lpthread -ljson-c

$(OUT_DIR)/discovery.o: $(DISCOVERY_UTIL_DIR)/discovery.c
	$(CC) -c -o $@ $< $(CFLAGS) -I$(PUB_INC) -I$(DISCOVERY_UTIL_DIR) $(LIB_INCS)

$(DISCOVERY_UTIL_EXEC): $(DISCOVERY_UTIL_OBJ) $(KINETIC_LIB) json
	@echo
	@echo --------------------------------------------------------------------------------
	@echo Building service discovery utility: $(DISCOVERY_UTIL_EXEC)
	@echo --------------------------------------------------------------------------------
	$(CC) -o $@ $(DISCOVERY_UTIL_OBJ) $(CFLAGS) $(DISCOVERY_UTIL_LDFLAGS) $(KINETIC_LIB)

discovery_utility: $(DISCOVERY_UTIL_EXEC)

build: discovery_utility




#-------------------------------------------------------------------------------
# Support for Simulator and Exection of Test Utility
#-------------------------------------------------------------------------------
+99 −0
Original line number Diff line number Diff line
/*
* kinetic-c
* Copyright (C) 2014 Seagate Technology.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include <stdio.h>

#include <err.h>
#include <errno.h>

#include <netinet/in.h>

#include "kinetic_client.h"
#include "socket99.h"
#include "json.h"

static int discover_service(void);


//------------------------------------------------------------------------------
// Main Entry Point Definition
int main(int argc, char** argv)
{
    // TODO: CLI args?
    (void)argc;
    (void)argv;
    return discover_service();
}
 
   
//------------------------------------------------------------------------------
// Service discovery

static int discover_service(void) {
    int v_true = 1;
    socket99_config cfg = {
        .host = INADDR_ANY,
        .port = KINETIC_PORT,
        .server = true,
        .datagram = true,
        .sockopts = {
            {/*SOL_SOCKET,*/ SO_BROADCAST, &v_true, sizeof(v_true)},
        },
    };
    socket99_result res;

    if (!socket99_open(&cfg, &res)) {
        errno = res.saved_errno;
        printf("res %d, %d\n", res.status, res.getaddrinfo_error);
        if (res.status == SOCKET99_ERROR_GETADDRINFO) {
            fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(res.getaddrinfo_error));
            return 1;
        }
        err(1, "socket99_open");
        return 1;
    }

    int one = 1;
    if (0 != setsockopt(res.fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one))) {
        err(1, "setsockopt");
    }

    char buf[1024];
    struct sockaddr_storage client_addr;
    socklen_t addr_len = sizeof(client_addr);

    /* TODO:
     *     + nonblocking, with max timeout
     *     + set up multicast on 239.1.2.3
     *     + if we receive any info, print it */

    for (;;) {
        ssize_t received = recvfrom(res.fd, buf, sizeof(buf), 0,
            (struct sockaddr *)&client_addr, &addr_len);

        if (received > 0) {
            buf[received] = '\0';
            printf("Got: '%s'\n", buf);
            /* TODO: sink into json, print decoded data. */
        }
    }
    
    return 0;
}
Original line number Diff line number Diff line
Subproject commit ec4879ac5b502ae81f6b73450b960ede11ad2560