Changeset - 1f2d007ac1cc
examples/0_three_forward/amy.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/0_three_forward/bob.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/1_load_pdl/amy.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/1_load_pdl/bob.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/1_socketlike/amy.c
Show inline comments
 
file renamed from examples/0_three_forward/amy.c to examples/1_socketlike/amy.c
examples/1_socketlike/bob.c
Show inline comments
 
file renamed from examples/0_three_forward/bob.c to examples/1_socketlike/bob.c
examples/1_socketlike/make.sh
Show inline comments
 
file renamed from examples/0_three_forward/make.sh to examples/1_socketlike/make.sh
examples/2_atomic_swap/amy.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/2_atomic_swap/bob.c
Show inline comments
 
deleted file
examples/2_atomic_swap/bob.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/2_dynamic_pdl/amy.c
Show inline comments
 
file renamed from examples/1_load_pdl/amy.c to examples/2_dynamic_pdl/amy.c
 
@@ -5,7 +5,7 @@
 
#include "../utility.c"
 

	
 
int main() { // AMY
 
	char * pdl = buffer_pdl("forward.pdl");
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	char msg_buf[128];
 
	memset(msg_buf, 0, 128);
examples/2_dynamic_pdl/bob.c
Show inline comments
 
file renamed from examples/1_load_pdl/bob.c to examples/2_dynamic_pdl/bob.c
 
@@ -3,7 +3,7 @@
 
#include "../utility.c"
 

	
 
int main() { // BOB!
 
	char * pdl = buffer_pdl("forward.pdl");
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	// BOB
 
	Connector* c = connector_new();
examples/2_dynamic_pdl/make.sh
Show inline comments
 
file renamed from examples/1_load_pdl/make.sh to examples/2_dynamic_pdl/make.sh
examples/3_nondeterminism/amy.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // AMY
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 

	
 
	check("config ", connector_configure(c, pdl, "sync"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_passive(c, 1, "127.0.0.1:7000"));
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int send_next = 0;
 
	char msg_buf[32];
 
	int code;
 
	int i;
 
	for (i = 0; 1; i++) {
 
		itoa(send_next, msg_buf, 10);
 
		
 
		printf("\nround %d. Will send msg `%s` next", i, msg_buf);
 
		
 
		
 
		// batch 0: no messages sent
 
		check("next_batch ", connector_next_batch(c));
 
		
 
		// batch 1: put 0
 
		check("put ", connector_put(c, 0, msg_buf, strlen(msg_buf) + 1));
 
		code = connector_sync(c, 3000);
 
		
 
		if (code == 0) printf("Sent no message!");
 
		else if (code == 1) {
 
			printf("Sent message `%s`!", msg_buf);
 
			send_next++;
 
		} else {
 
			printf(
 
				"Connector error! %d (%s)\nBreaking loop!\n",
 
				code, connector_error_peek()
 
			);
 
			break;
 
		}
 
	}
 
	
 
	printf("destroying...\n");
 
	connector_destroy(c);
 
	printf("exiting...\n");
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/3_nondeterminism/bob.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // BOB!
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	Connector* c = connector_new();
 

	
 
	printf("configuring...\n");
 
	check("config ", connector_configure(c, pdl, "sync"));
 

	
 
	check("bind 0 ", connector_bind_active(c, 0, "127.0.0.1:7000"));
 
	check("bind 1 ", connector_bind_native(c, 1));
 

	
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int msg_len;
 
	const unsigned char * msg;
 

	
 
	int i;
 
	srand(time(NULL));
 
	for (i = 0; i < 10; i++) {
 
		printf("\nround %d...\n", i);
 
		int random = rand() % 2;
 
		if (random == 0) {
 
			printf("I don't want a message!\n");
 
			check("sync", connector_sync(c, 1000));
 
		} else {
 
			printf("I want a message!\n");
 
			check("get ", connector_get(c, 0));
 
			check("sync", connector_sync(c, 1000));
 
			check("read msg", connector_gotten(c, 0, &msg, &msg_len));
 
			printf("Got message: `%.*s`\n", msg_len, msg);
 
		}
 
	}
 
	
 
	printf("destroying...\n");
 
	connector_destroy(c);
 
	printf("exiting...\n");
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/3_nondeterminism/make.sh
Show inline comments
 
file renamed from examples/2_atomic_swap/make.sh to examples/3_nondeterminism/make.sh
examples/4_atomicity/amy.c
Show inline comments
 
file renamed from examples/2_atomic_swap/amy.c to examples/4_atomicity/amy.c
 
@@ -5,12 +5,12 @@
 
#include "../utility.c"
 

	
 
int main() { // AMY
 
	char * pdl = buffer_pdl("swap.pdl");
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 

	
 
	check("config ", connector_configure(c, pdl, "forward_two"));
 
	check("config ", connector_configure(c, pdl, "sync_two"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_native(c, 1));
 
	check("bind 2 ", connector_bind_passive(c, 2, "127.0.0.1:7000"));
 
@@ -19,14 +19,27 @@ int main() { // AMY
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int i;
 
	for (i = 0; i < 3; i++) {
 
	int code;
 
	while (1) {
 
		printf("\nround %d\n", i);
 
		
 
		// batch 0: no messages sent
 
		check("next_batch ", connector_next_batch(c));
 
		
 
		// batch 1: put 0 and put 1
 
		check("put ", connector_put(c, 0, "one", 3));
 
		check("put ", connector_put(c, 1, "two", 3));
 
		check("sync", connector_sync(c, 1000));
 
		code = connector_sync(c, 3000);
 
		
 
		printf("Sent both messages!\n");
 
		if (code == 0) printf("Sent neither message!");
 
		else if (code == 1) printf("Sent both messages!");
 
		else {
 
			printf(
 
				"Connector error! %d (%s)\nBreaking loop!\n",
 
				code, connector_error_peek()
 
			);
 
			break;
 
		}
 
	}
 
	
 
	printf("destroying...\n");
examples/4_atomicity/bob.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // BOB!
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	Connector* c = connector_new();
 

	
 
	printf("configuring...\n");
 
	check("config ", connector_configure(c, pdl, "sync_two"));
 

	
 
	check("bind 0 ", connector_bind_active(c, 0, "127.0.0.1:7000"));
 
	check("bind 1 ", connector_bind_active(c, 1, "127.0.0.1:7001"));
 
	check("bind 2 ", connector_bind_native(c, 2));
 
	check("bind 3 ", connector_bind_native(c, 3));
 

	
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int msg_len;
 
	const unsigned char * msg;
 

	
 
	int i;
 
	
 
	// rounds 0..=2: get both messages
 
	for (i = 0; i <= 2; i++) {
 
		printf("\nround %d\n", i);
 
		
 
		check("get ", connector_get(c, 0));
 
		check("get ", connector_get(c, 1));
 
		check("sync", connector_sync(c, 1000));
 
		
 
		check("read one", connector_gotten(c, 0, &msg, &msg_len));
 
		printf("Got message one: `%.*s`\n", msg_len, msg);
 
		
 
		check("read two", connector_gotten(c, 1, &msg, &msg_len));
 
		printf("Got message two: `%.*s`\n", msg_len, msg);
 
	}
 
	// rounds 3..=5: get neither message
 
	for (i = 3; i <= 5; i++) {
 
		printf("\nround %d\n", i);
 
		
 
		//check("get ", connector_get(c, 0));
 
		//check("get ", connector_get(c, 1));
 
		check("sync", connector_sync(c, 3000));
 
		
 
		//check("read one", connector_gotten(c, 0, &msg, &msg_len));
 
		//printf("Got message one: `%.*s`\n", msg_len, msg);
 
		
 
		//check("read two", connector_gotten(c, 1, &msg, &msg_len));
 
		//printf("Got message two: `%.*s`\n", msg_len, msg);
 
	}
 
	// round 6: attempt to get just one message
 
	for (i = 6; i <= 6; i++) {
 
		printf("\nround %d\n", i);
 
		
 
		check("get ", connector_get(c, 0));
 
		//check("get ", connector_get(c, 1));
 
		check("sync", connector_sync(c, 3000));
 
		
 
		//check("read one", connector_gotten(c, 0, &msg, &msg_len));
 
		//printf("Got message one: `%.*s`\n", msg_len, msg);
 
		
 
		check("read two", connector_gotten(c, 1, &msg, &msg_len));
 
		printf("Got message two: `%.*s`\n", msg_len, msg);
 
	}
 
	
 
	printf("destroying...\n");
 
	connector_destroy(c);
 
	printf("exiting...\n");
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/4_atomicity/make.sh
Show inline comments
 
new file 100644
 
#!/bin/sh
 

	
 
LIB_PATH="../"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH amy.c -o amy
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH bob.c -o bob
examples/5_recovery/amy.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // AMY
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 

	
 
	check("config ", connector_configure(c, pdl, "sync"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_passive(c, 1, "127.0.0.1:7000"));
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 
	
 
	int i;
 
	int code;
 
	while (1) {
 
		printf("\nround %d. I will offer the message \"hello\".\n", i);
 
		connector_next_batch(c);
 
		check("put ", connector_put(c, 0, "hello", 5));
 
		code = connector_sync(c, 3000);
 
		
 
		if (code == 0) printf("OK! No message was sent!");
 
		else if (code == 1) printf("OK! My message was received!");
 
		else if (code == -1) printf("!!! UH OH! The round rolled back! Let's try again");
 
		else {
 
			printf(
 
				"Something went wrong!\n",
 
				code, connector_error_peek()
 
			);
 
			break;
 
		}
 
	}
 
	
 
	printf("destroying...\n");
 
	connector_destroy(c);
 
	printf("exiting...\n");
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/5_recovery/amy.exe
Show inline comments
 
new file 100644
 
binary diff not shown
examples/5_recovery/bob.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // BOB!
 

	
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	Connector* c = connector_new();
 

	
 
	printf("configuring...\n");
 
	check("config ", connector_configure(c, pdl, "recovery_bob"));
 
	check("bind 0 ", connector_bind_active(c, 0, "127.0.0.1:7000"));
 
	check("bind 1 ", connector_bind_native(c, 1));
 

	
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int msg_len;
 
	const unsigned char * msg;
 

	
 
	int i;
 
	char msg_buf[1];
 
	int code;
 
	char answer;
 
	
 
	for (i = 0; true; i++) {
 
		printf("\nround %d...\n", i);
 
		printf("Should I receive a message? (y/n): ");
 
		scanf(" %c", &answer);
 
		if (answer == 'y') {
 
			printf("OK! Let's receive a message!\n");
 
			connector_get(c, 0);
 
		} else if (answer == 'n') {
 
			printf("OK! Let's NOT receive a message!\n");
 
		} else {
 
			printf("Expected (y/n) input!");
 
			continue;
 
		}
 
		
 
		code = connector_sync(c, 1000);
 
			
 
		// lets see how it went
 
		if (code == 0) {
 
			printf("Success!\n");
 
			if (answer == 'y') {
 
				check("read ", connector_gotten(c, 0, &msg, &msg_len));
 
				printf("Got message: `%.*s`\n", msg_len, msg);
 
			}
 
		} else if (code == -1) {
 
			printf("!!! UH OH! The round rolled back! Let's try again\n");
 
		} else {
 
			printf(
 
				"Something went wrong!\n",
 
				code, connector_error_peek()
 
			);
 
			break;
 
		}
 
	}
 
	
 
	printf("destroying...\n");
 
	connector_destroy(c);
 
	printf("exiting...\n");
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/5_recovery/bob.exe
Show inline comments
 
new file 100644
 
binary diff not shown
examples/5_recovery/make.sh
Show inline comments
 
new file 100644
 
#!/bin/sh
 

	
 
LIB_PATH="../"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH amy.c -o amy
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH bob.c -o bob
examples/6_constraint_solve/THIS IS TODO.txt
Show inline comments
 
new file 100644
examples/6_constraint_solve/main.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <time.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main(int arg_c, char * argv[]) {
 
	int index;
 
	if (arg_c != 2) {
 
		printf("Expected one arg: which peer I am in 0..4");
 
		return 1;
 
	}
 
	index = atoi(argv[1]);
 
	printf("I am peer %d\n", index);
 
	
 
	const char* addrs[] = {
 
		"127.0.0.1:7000",
 
		"127.0.0.1:7001",
 
		"127.0.0.1:7002",
 
		"127.0.0.1:7003",
 
		"127.0.0.1:7004",
 
		"127.0.0.1:7005",
 
	};
 

	
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 

	
 
	check("config ", connector_configure(c, pdl, "xor_three"));
 
	int i, j;
 
	int addr_index = 0;
 
	int port = 0;
 
	for (i = 0; i < 4; i++) {
 
		for (j = i+1; j < 4; j++) {
 
			if (i==index) {
 
				printf("ports %d and %d are for a passive channel to peer %d over addr %s\n", port, port+1, j, addrs[addr_index]);
 
				check("bind an ", connector_bind_native(c, port));
 
				port++;
 
				check("bind a  ", connector_bind_active(c, port, addrs[addr_index]));
 
				port++;
 
			} else if (j==index) {
 
				printf("ports %d and %d are for an active channel to peer %d over addr %s\n", port, port+1, i, addrs[addr_index]);
 
				check("bind p  ", connector_bind_passive(c, port, addrs[addr_index]));
 
				port++;
 
				check("bind pn ", connector_bind_native(c, port));
 
				port++;
 
			}
 
			addr_index++;
 
		}
 
	}
 
	check("connect", connector_connect(c, 5000));
 
	
 
	for (i = 0; i < 4; i++) {
 
		if (i == index) continue;
 
		// another batch
 
		for (j = 0; j < 4; j++) {
 
			
 
		}
 
	}
 
	connector_sync();
 
	
 
	printf("destroying...\n");
 
	connector_destroy(c);
 
	printf("exiting...\n");
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/6_constraint_solve/main.exe
Show inline comments
 
new file 100644
 
binary diff not shown
examples/6_constraint_solve/make.sh
Show inline comments
 
new file 100644
 
#!/bin/sh
 

	
 
LIB_PATH="../"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH main.c -o main
examples/eg_protocols.pdl
Show inline comments
 
new file 100644
 
primitive forward(in i, out o) {
 
	while(true) synchronous {
 
		put(o, get(i));
 
	}
 
}
 
primitive sync(in i, out o) {
 
	while(true) synchronous {
 
		if(fires(i)) {
 
			put(o, get(i));
 
		}
 
	}
 
}
 

	
 
primitive sync_two(in ia, in ib, out oa, out ob) {
 
	while(true) synchronous {
 
		if (fires(ia)) {
 
			put(oa, get(ia));
 
			put(ob, get(ib));
 
		}
 
	}
 
}
 

	
 
composite recovery_bob(in i, out o) {
 
	new sync(i, o);
 
}
 

	
 
primitive xor_three(in ai, out ao, in bi, out bo, in ci, out co) {
 
	synchronous {
 
		if      (fires(ai)) put(ao, get(ai));
 
		else if (fires(bi)) put(bo, get(bi));
 
		else                put(co, get(ci)); 
 
	}
 
}
 
\ No newline at end of file
examples/forward.pdl
Show inline comments
 
deleted file
examples/utility.c
Show inline comments
 
@@ -12,7 +12,7 @@ void check(const char* phase, int err) {
 

	
 
// allocates a buffer!
 
char * buffer_pdl(char * filename) {
 
	FILE *f = fopen("forward.pdl", "rb");
 
	FILE *f = fopen(filename, "rb");
 
	if (f == NULL) {
 
		printf("Opening pdl file returned errno %d!\n", errno);
 
		exit(1);
reowolf.h
Show inline comments
 
@@ -69,6 +69,12 @@ int connector_connect(Connector *connector, uint64_t timeout_millis);
 
 */
 
void connector_destroy(Connector *connector);
 

	
 
/**
 
 * # Safety
 
 * TODO
 
 */
 
int connector_dump_log(Connector *connector);
 

	
 
/**
 
 * Resets the error message buffer.
 
 * Returns:
 
@@ -138,10 +144,4 @@ int connector_sync(Connector *connector, uint64_t timeout_millis);
 
 */
 
Connector *connector_with_controller_id(ControllerId controller_id);
 

	
 
/**
 
 * # Safety
 
 * TODO
 
 */
 
int port_close(Connector *connector, unsigned int _proto_port_index);
 

	
 
#endif /* REOWOLF_HEADER_DEFINED */
src/runtime/connector.rs
Show inline comments
 
@@ -147,7 +147,7 @@ impl Connector {
 
            _ => return Err(()),
 
        };
 
        connected.sync_batches.push(SyncBatch::default());
 
        Ok(connected.sync_batches.len() - 1)
 
        Ok(connected.sync_batches.len() - 2)
 
    }
 

	
 
    pub fn sync(&mut self, timeout: Duration) -> Result<usize, SyncErr> {
src/runtime/ffi.rs
Show inline comments
 
@@ -278,7 +278,10 @@ pub unsafe extern "C" fn connector_put(
 
/// # Safety
 
/// TODO
 
#[no_mangle]
 
pub unsafe extern "C" fn connector_get(connector: *mut Connector, proto_port_index: c_uint) -> c_int {
 
pub unsafe extern "C" fn connector_get(
 
    connector: *mut Connector,
 
    proto_port_index: c_uint,
 
) -> c_int {
 
    let mut b = Box::from_raw(connector); // unsafe!
 
    let ret = b.get(proto_port_index.try_into().unwrap());
 
    Box::into_raw(b); // don't drop!
 
@@ -324,11 +327,17 @@ pub unsafe extern "C" fn connector_gotten(
 
/// # Safety
 
/// TODO
 
#[no_mangle]
 
pub unsafe extern "C" fn port_close(connector: *mut Connector, _proto_port_index: c_uint) -> c_int {
 
    let b = Box::from_raw(connector); // unsafe!
 
                                      // TODO
 
pub unsafe extern "C" fn connector_dump_log(connector: *mut Connector) -> c_int {
 
    let mut b = Box::from_raw(connector); // unsafe!
 
    let result = match b.get_mut_logger() {
 
        Some(s) => {
 
            println!("{}", s);
 
            0
 
        }
 
        None => 1,
 
    };
 
    Box::into_raw(b); // don't drop!
 
    0
 
    result
 
}
 

	
 
/// # Safety
 
@@ -354,9 +363,10 @@ pub unsafe extern "C" fn connector_sync(connector: *mut Connector, timeout_milli
 
    let mut b = Box::from_raw(connector); // unsafe!
 
    let result = match b.sync(Duration::from_millis(timeout_millis)) {
 
        Ok(batch_index) => batch_index.try_into().unwrap(),
 
        Err(SyncErr::Timeout) => -1, // timeout!
 
        Err(e) => {
 
            overwrite_last_error(format!("{:?}", e).as_bytes());
 
            -1
 
            -2
 
        }
 
    };
 
    Box::into_raw(b); // don't drop!
0 comments (0 inline, 0 general)