Commits

Mechiel Lukkien  committed 50e73ff Draft

third release. from tarball.

"Binds on ip6 addresses too. Previously, memventi only bound to ip4
addresses... This release also fixes a tiny buglet only seen when
listening on many network addresses (>32)."

  • Participants
  • Parent commits 28f9cb7

Comments (0)

Files changed (4)

 
 enum {
 	Magicsize	= 4,
-	Tablemagicsize	= 4,
 	Scoresize	= 20,
 	Indexscoresize	= 8,
 	Diskiheadersize	= Indexscoresize+1+6,
 	Stringmax	= 1024,
 
 	Headermagic	= 0x2f9d81e5,
-	Indexmagic	= 0x119dab59,
-	Tablemagic	= 0x5dc31acd,
 };
-/*	Tableheadersize = Tablemagisize+1+ */
 
 
 typedef struct DHeader DHeader;
 static pthread_t readlistenthread[Listenmax];
 static pthread_t writelistenthread[Listenmax];
 static pthread_t syncprocthread;
+static int nreadaddrs, nwriteaddrs;
 static int nreadlistens, nwritelistens;
 
 static uvlong nlookups;
 	Vmsg in, out;
 	char buf[128];
 	char *l;
-	char handshake[] = "venti-02-simple\n";
+	char handshake[] = "venti-02-memventi\n";
 	DHeader dh;
 	int ok, okhdr;
 	int len;
 			if(allowwrite)
 				safe_sync();
 			break;
+		case Tping:
+			break;
 		case Tgoodbye:
 			if(allowwrite)
 				safe_sync();
 
 
 int
-dobind(Netaddr *netaddr)
+dobind(int *fds, int fdi, Netaddr *netaddr)
 {
-	struct sockaddr bound;
-	socklen_t boundlen;
 	int gaierr;
-	struct addrinfo *addrs;
-        struct addrinfo localhints = { AI_PASSIVE, PF_INET, SOCK_STREAM, 0, 0, NULL, NULL, NULL };
-	int listenfd;
+	struct addrinfo *addrs0, *addrs;
+	struct addrinfo localhints;
+	int n;
+	int fd;
 
-	listenfd = socket(PF_INET, SOCK_STREAM, 0);
-	if(listenfd < 0)
-		errsyslog(1, "socket");
+	memset(&localhints, 0, sizeof localhints);
+	localhints.ai_family = PF_UNSPEC;
+	localhints.ai_socktype = SOCK_STREAM;
+	localhints.ai_flags = AI_PASSIVE;
 
 	gaierr = getaddrinfo(netaddr->host, netaddr->port, &localhints, &addrs);
 	if(gaierr)
 		errxsyslog(1, "getaddrinfo: %s", gai_strerror(gaierr));
+	addrs0 = addrs;
 
-	boundlen = addrs->ai_addrlen;
-	memcpy(&bound, addrs->ai_addr, boundlen);
-	freeaddrinfo(addrs);
+	n = 0;
+	for(; addrs != nil; addrs = addrs->ai_next) {
+		fd = socket(addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol);
+		if(fd < 0)
+			errsyslog(1, "socket");
 
-	if(bind(listenfd, &bound, boundlen) != 0)
-		errsyslog(1, "bind");
+		if(bind(fd, addrs->ai_addr, addrs->ai_addrlen) != 0)
+			errsyslog(1, "bind");
 
-	if(listen(listenfd, 1) != 0)
-		errsyslog(1, "listen");
-
-	return listenfd;
+		if(listen(fd, 5) != 0)
+			errsyslog(1, "listen");
+		if(fdi >= Listenmax)
+			errsyslog(1, "too many sockets");
+		fds[fdi++] = fd;
+		n += 1;
+	}
+	freeaddrinfo(addrs0);
+	return n;
 }
 
 
 
 	fflag = 0;
 	vflag = 0;
-	nreadlistens = nwritelistens = 0;
+	nreadaddrs = nwriteaddrs = 0;
 	while((ch = getopt(argc, argv, "Dfvd:i:r:w:")) != -1) {
 		switch(ch) {
 		case 'D':
 			indexfile = optarg;
 			break;
 		case 'r':
-			if(nreadlistens == nelem(readaddrs))
+			if(nreadaddrs == nelem(readaddrs))
 				errxsyslog(1, "too many read-only hosts specified");
-			netaddr = &readaddrs[nreadlistens++];
+			netaddr = &readaddrs[nreadaddrs++];
 			netaddr->port = strrchr(optarg, '!');
 			if(netaddr->port != nil)
 				*netaddr->port++ = '\0';
 			netaddr->host = optarg;
 			break;
 		case 'w':
-			if(nreadlistens == nelem(writeaddrs))
+			if(nwriteaddrs == nelem(writeaddrs))
 				errxsyslog(1, "too many read/write hosts specified");
-			netaddr = &writeaddrs[nwritelistens++];
+			netaddr = &writeaddrs[nwriteaddrs++];
 			netaddr->port = strrchr(optarg, '!');
 			if(netaddr->port != nil)
 				*netaddr->port++ = '\0';
 	endaddr = (1ULL<<addrwidth)-1;
 	mementrysize = 8+entryscorewidth+addrwidth;
 
-	if(nreadlistens == 0 && nwritelistens == 0) {
+	if(nreadaddrs == 0 && nwriteaddrs == 0) {
 		writeaddrs[0].host = "localhost";
 		writeaddrs[0].port = defaultport;
-		nwritelistens++;
+		nwriteaddrs++;
 	}
 
 	openlog("memventi", LOG_CONS|(fflag ? LOG_PERROR : 0), LOG_DAEMON);
 	setlogmask(LOG_UPTO(vflag ? LOG_DEBUG : LOG_NOTICE));
 
-	for(i = 0; i < nreadlistens; i++)
-		readfds[i] = dobind(&readaddrs[i]);
-	for(i = 0; i < nwritelistens; i++)
-		writefds[i] = dobind(&writeaddrs[i]);
+	nreadlistens = nwritelistens = 0;
+	for(i = 0; i < nreadaddrs; i++)
+		nreadlistens += dobind(readfds, nreadlistens, &readaddrs[i]);
+	for(i = 0; i < nwriteaddrs; i++)
+		nwritelistens += dobind(writefds, nwritelistens, &writeaddrs[i]);
 
 	sigemptyset(&mask);
 	sigaddset(&mask, SIGPIPE);
 	m->data = nil;
 	switch(m->op) {
 	case Thello:
-		if(readstr(&p, end, nil, 0) == 0)
+		if(readstr(&p, end, nil, 0) == 0)	/* version */
 			return 0;
-		if(readstr(&p, end, nil, 0) == 0)
+		if(readstr(&p, end, nil, 0) == 0)	/* uid */
 			return 0;
 		if(p+1 > end)
 			return 0;
+note: ventisrv, written in limbo during the google summer of code 2007,
+superseded memventi.  the list below is likely to never get finished.
+
 - read 16 last disk entries (using index offset as start) and verify
 - multiple procs for accessing datafile, reads concurrent, stores queued.
 - try to read index faster