Native: cleanup and refactor: add upport/downport args to connect_sockets

This commit is contained in:
Ryan Newton 2018-12-11 09:30:19 -08:00
Родитель 9ec0dae746
Коммит c0676ec63d
6 изменённых файлов: 27 добавлений и 45 удалений

Просмотреть файл

@ -53,8 +53,6 @@ enum MsgType { RPC=0, //
// FIXME: these should become PRIVATE to the library:
extern int g_to_immortal_coord, g_from_immortal_coord;
extern int upport, downport;
// Communicates with the server to establish normal operation.
//
@ -62,9 +60,14 @@ extern int upport, downport;
// received from a call to connect_sockets.
void startup_protocol(int upfd, int downfd);
// Connect the
void connect_sockets(int* upptr, int* downptr);
// Connect to the ImmortalCoordinator. Use the provided ports.
//
// On the "up" port we connect, and on "down" the coordinator connects
// to us. This function writes the file descriptors for the opened
// connections into the pointers provided as the last two arguments.
void connect_sockets(int upport, int downport, int* up_fd_ptr, int* down_fd_ptr);
// Encoding and Decoding message types
//------------------------------------------------------------------------------
// PRECONDITION: sufficient space free at output pointer.
@ -94,6 +97,8 @@ void amb_send_outgoing_rpc(void* tempbuf, char* dest, int32_t destLen, char RPC_
void amb_recv_log_hdr(int sockfd, struct log_hdr* hdr);
//------------------------------------------------------------------------------
// TEMP - audit me
void attach_if_needed(char* dest, int destLen);

Просмотреть файл

@ -25,18 +25,12 @@
#include "ambrosia/client.h"
#include "ambrosia/internal/bits.h"
// Library-level global variables:
// Library-level (private) global variables:
// --------------------------------------------------
// FIXME: looks like we need a hashtable after all...
int g_attached = 0; // For now, ONE destination.
// This follows the rule that the RECV side acts as the server:
int upport = 1000; // Send. Up to the reliability-coordinator-as-server
int downport = 1001; // Recv. Down from the coordinator (we're server)
// Global variables that should be initialized once for the library.
// We can ONLY ever have ONE reliability coordinator.
int g_to_immortal_coord, g_from_immortal_coord;
@ -189,27 +183,6 @@ void* amb_write_outgoing_rpc(void* buf, char* dest, int32_t destLen, char RPC_or
return (void*)cursor;
}
// This is a convenience method that sits above the buffer API:
// ------------------------------------------------------------
/*
// Logically the same as send_outgoing_*, except uses the global buffer.
// PRECONDITION: buffer is free / no outstanding "reserve" that needs to be released.
void buffer_outgoing_rpc_hdr(char* dest, int32_t destLen, char RPC_or_RetVal,
int32_t methodID, char fireForget, int argsLen) {
// Overestimate the space needed:
int sizeBound = (1 // type tag
+ 5 + destLen + 1 // RPC_or_RetVal
+ 5 + 1 // fireForget
+ 5);
char* start = reserve_buffer(sizeBound);
char* end = amb_write_outgoing_rpc_hdr(start, dest,destLen,RPC_or_RetVal,methodID,fireForget,argsLen);
// If we want to create RPCBatch messages we need to only send complete messages, not just headers:
finished_reserve_buffer(end-start);
}
*/
// Direct socket sends/recvs
// ------------------------------
@ -308,7 +281,7 @@ void enable_fast_loopback(SOCKET sock) {
}
}
void connect_sockets(int* upptr, int* downptr) {
void connect_sockets(int upport, int downport, int* upptr, int* downptr) {
WSADATA wsa;
SOCKET sock;
@ -467,7 +440,7 @@ void connect_sockets(int* upptr, int* downptr) {
// Establish both connections with the reliability coordinator.
// Takes two output parameters where it will write the resulting sockets.
void connect_sockets(int* upptr, int* downptr) {
void connect_sockets(int upport, int downport, int* upptr, int* downptr) {
#ifdef IPV4
struct hostent* immortalCoord;
struct sockaddr_in addr;
@ -597,6 +570,7 @@ void startup_protocol(int upfd, int downfd) {
case TakeBecomingPrimaryCheckpoint:
amb_debug_log("Starting up for the first time (TakeBecomingPrimaryCheckpoint)\n");
break;
case Checkpoint:
fprintf(stderr, "RECOVER mode ... not implemented yet.\n");

Просмотреть файл

@ -230,10 +230,6 @@ char* reserve_buffer(int len)
void release_buffer(int len)
{
// finished_reserve_buffer(len);
// g_buffer_tail += g_buffer_total_reserved; // Publish it!
// g_buffer_total_reserved = 0;
spsc_rring_debug_log(" => release_buffer of %d bytes, new tail %d\n", len, g_buffer_tail + len);
if (len > g_buffer_last_reserved) {

Просмотреть файл

@ -23,11 +23,12 @@
# Oh, that's happening even on ambrosia-dev:
FROM ambrosia-dev
# We get build dependencies from ambrosia-dev, since it built the native library.
# RUN apt-get update && \
# apt-get install -y make gcc
# nmap
RUN apt-get update && \
apt-get install -y make gcc nmap
ADD . /ambrosia/NativeService
ADD . /ambrosia/NativeService
WORKDIR /ambrosia/NativeService
ENV AMBROSIA_BINDIR=/ambrosia/bin

Просмотреть файл

@ -611,10 +611,12 @@ void reset_trial_state() {
}
}
int main(int argc, char** argv)
{
// How big to allocate the buffer:
int buffer_bytes_allocated = -1; // Ivar semantics - write once.
int upport, downport;
srand(time(0));
@ -650,6 +652,7 @@ int main(int argc, char** argv)
destLen = strlen(destName);
upport = atoi(argv[3]);
downport = atoi(argv[4]);
} else {
fprintf(stderr, "Usage: this executable expects args: <role=0/1/2/3> <destination> <port> <port> [roundsz] [trials] [bufsz]\n");
fprintf(stderr, " where <role> is 0/1 for sender/receiver throughput mode\n");
@ -681,7 +684,7 @@ int main(int argc, char** argv)
/* printf("(You need four ports, in the above example: 50000-50003 .)\n"); */
int upfd, downfd;
connect_sockets(&upfd, &downfd);
connect_sockets(upport, downport, &upfd, &downfd);
amb_debug_log("Connections established (%d,%d), beginning protocol.\n", upfd, downfd);
startup_protocol(upfd, downfd);

Просмотреть файл

@ -40,17 +40,20 @@ echo
$DOCKER build -t ${TAG1A} .
if ! [[ ${DONT_BUILD_RELEASE_IMAGE:+defined} ]]; then
echo;echo "Building Release Image: $TAG1B"; echo
$DOCKER build -f Dockerfile.release -t ${TAG1B} .
fi
if ! [[ ${DONT_BUILD_APP_IMAGES:+defined} ]]; then
if ! [[ ${DONT_BUILD_PTI_IMAGE:+defined} ]]; then
if ! [[ ${DONT_BUILD_PTI_IMAGE:+defined} ]]; then
echo;echo "Building App Image: $TAG2"; echo
cd "$AMBROSIA_ROOT"/InternalImmortals/PerformanceTestInterruptible
$DOCKER build -t ${TAG2} .
cd "$AMBROSIA_ROOT"
fi
if ! [[ ${DONT_BUILD_NATIVE_IMAGE:+defined} ]]; then
if ! [[ ${DONT_BUILD_NATIVE_IMAGE:+defined} ]]; then
echo;echo "Building App Image: $TAG3"; echo
cd "$AMBROSIA_ROOT"/InternalImmortals/NativeService
docker build -t ${TAG3} .
cd "$AMBROSIA_ROOT"