Commit Graph

1440 Commits

Author SHA1 Message Date
Joris Vink 9cfcd9a4be JSON API improvements.
- Try harder to mark integers as KORE_JSON_TYPE_INTEGER, especially if
  they fit in the internal representation of one (int64_t).

- Move error codes into the JSON code itself, rather then requiring
  a kore_json data structure. This allows the JSON API to relay errors
  such as "item not found" or "type mismatch" properly when looking at items.

- When asking for a KORE_JSON_TYPE_INTEGER_U64 and a KORE_JSON_TYPE_INTEGER
  was found with the same name, check if it could be returned properly and do
  so if possible.
2021-03-30 14:19:48 +02:00
Joris Vink 0549295f30 Cleanup integer types for # Python arguments.
Define PY_SSIZE_T_CLEAN before pulling in Python.h
2021-01-28 13:34:43 +01:00
Joris Vink c36a7759f1 Get Kore to build with Python 3.10.0a3. 2021-01-28 10:17:02 +01:00
Daniel Fahlgren 017bbff881 Neither 'in' not 'pad' are format specifiers. Replace with a call to
kore_buf_append() instead. At best 'len' is unused, but if 'in' contains a
percentage sign bad things might happen.
2021-01-14 13:31:27 +01:00
Joris Vink 4e2ca90095 Move Kore hook functions to kore/hooks.h. 2021-01-11 23:58:26 +01:00
Joris Vink cef5ac4003 bump copyright year. 2021-01-11 23:46:08 +01:00
Joris Vink 37f85ed663 rename foreground to kore_foreground. 2021-01-11 23:35:16 +01:00
Joris Vink 599617e7b4 More ACME protocol improvements.
- Make sure tls-alpn01 works even if the underlying SSL library ends up
  calling the ALPN callback *before* the SNI extension was parsed and
  the correct domain was selected.

LibreSSL still does this, and older OpenSSL did too I believe, however
OpenSSL grew a clue and always makes sure SNI is called first.

Yes, TLS extensions have no fixed order but it still makes sense to
notify applications using your library of the SNI extension first
before anything else almost.

Oh well.
2021-01-05 23:25:29 +01:00
Joris Vink 4cace25330 Acme protocol updates.
- Adds POST-as-GET for all GET requests that would support it.
2021-01-05 22:01:36 +01:00
Joris Vink cb0f5a4137 Make sure koreapp.onmsg can log errors from Python. 2020-12-18 19:48:17 +01:00
Joris Vink d10ee4438d Duplicate __progname for the call to openlog().
Kore will mangle the argv[] array for setting process names in
a more friendly way but that could cause syslog to spew mangled
data as the ident.
2020-12-08 11:33:26 +01:00
Joris Vink 9227347b90 Fix concurrency problem in coroutines.
If a coroutine is woken up from another coroutine running from an
http request we can end up in a case where the call path looks like:

0 kore_worker_entry
1 epoll wait		<- bound to pending timers
2 http_process		<- first coro sleep
3 kore_python_coro_run	<- wakes up request
4 http_process		<- wakes up another coroutine
5 return to kore_worker_entry

In the case where 4 wakes up another coroutine but 1 is bound to a timer
and no io activity occurs the coroutine isn't run until the timer fires.

Fix this issue by always checking for pending coroutines even if the
netwait isn't INFINITE.
2020-12-07 11:11:21 +01:00
Joris Vink fd2cda5a43 include inttypes.h in json.c 2020-11-27 16:34:38 +01:00
Joris Vink 5421b7726e kore_json_init() should take a const void for the data. 2020-11-23 10:48:04 +01:00
Joris Vink 802a78c0b0 Make sure we check if consume whitespace failed. 2020-11-21 13:01:42 +01:00
Joris Vink d7fbce37f5 Better parsing of JSON integers and numbers.
Add 2 new types:
	KORE_JSON_TYPE_INTEGER
		signed integer type, internally stored as s64.

	KORE_JSON_TYPE_INTEGER_U64
		unsigned integer type, internally stored as u64.

Kore JSON parser will prefer marking integers as INTEGER_U64 if it
was unsigned and did not have fractions.
2020-11-19 14:56:17 +01:00
Joris Vink 760dff8b3c allow tab escape in JSON strings. 2020-11-19 09:55:41 +01:00
Joris Vink e712e3a951 consume any initial whitespace in JSON data. 2020-11-19 09:22:16 +01:00
Joris Vink 8008fe8b60 Don't allow unknown escaped characters in JSON parser. 2020-11-19 09:10:12 +01:00
Joris Vink 8c32f8f63b Small improvements to JSON parser.
- Don't allow garbage at the end of the JSON data (except whitespace).
- Don't allow objects such as {"a":"b",} or [a,]
2020-11-19 09:07:42 +01:00
Joris Vink 90bf36a37b whitespace 2020-10-28 15:44:18 +01:00
Joris Vink 262a2512f1 Do not dispatch signals to workers without a valid pid.
thanks rille.
2020-10-16 13:06:08 +02:00
Joris Vink 67cf3e872b Add kore_default_getopt().
This handles the default option parsing in Kore and should be called
by single_binary=yes builds in kore_parent_configure() unless they
want to handle their own argument parsing.
2020-10-08 13:51:50 +02:00
Joris Vink 4313c0eab5 Python: Add kore.socket.recvmsg()
Returns the ancillary data to the caller as a list.
2020-10-02 11:27:52 +02:00
Frederic Cambus af99a4d9e2 Conditionally allow syscalls required to run on arm.
Those syscalls do not exist on other Kore supported platforms, so we
must check that they exist before allowing them.
2020-09-17 17:41:03 +02:00
Frederic Cambus 28ea1b3c7e Add missing tests for SYS_mmap, fixes the build on arm. 2020-09-17 17:41:00 +02:00
Frederic Cambus 7290944bf3 Add support for logging seccomp violations on arm.
On ARM EABI, the syscall number can be read from register r7.
2020-09-16 23:07:45 +02:00
Frederic Cambus 9deb2e71bf Use kore_worker_name() when logging worker exits in worker_reaper(). 2020-09-15 12:19:08 +02:00
Frederic Cambus 60bc618c3f Allow the clock_nanosleep syscall, it is required for kore_accesslog().
glibc 2.31 calls clock_nanosleep in its nanosleep function.
2020-09-14 19:15:25 +02:00
Joris Vink 51e9c64fc0 strdup the application name. 2020-09-09 22:30:56 +02:00
Joris Vink cdb45118e2 kill unused variable 2020-09-09 22:22:54 +02:00
Joris Vink 4e384167f0 The version.c file has moved.
Therefor make sure kodev knows the correct place to look for it
and include it in single binary builds.
2020-09-09 21:27:07 +02:00
Joris Vink 2dca8fd6cc Add an install-sources target.
This will place the required sources for building
single binary builds under $PREFIX/share/kore.

The kodev utility will now pickup this KORE_SOURCE path automatically
unless another one is given via the conf/build.conf file or the KORE_SOURCE
environment path.
2020-09-09 21:09:40 +02:00
Joris Vink d7dd9707d7 Remove getopt() for KORE_SINGLE_BINARY.
If KORE_SINGLE_BINARY is enabled, remove the getopt() call that
Kore does itself. This way all arguments are passed to the
kore_parent_configure() hook as-is allowing developers to
more easily implement their own option handling.
2020-09-08 22:38:06 +02:00
Joris Vink f6af4a27f4 Enable type-limits warning.
Remove unneeded comparison in the JSON code.
via https://marc.info/?l=openbsd-ports&m=159958572325174&w=2
2020-09-08 19:29:15 +02:00
Joris Vink aaf8be40c2 Add casts for isxdigit and isspace.
The argument must be representable as an unsigned char or EOF.
2020-09-08 19:19:56 +02:00
Frederic Cambus 3ac956c67d Use kore_worker_name() when logging worker shutdowns. 2020-09-08 15:15:33 +02:00
Frederic Cambus d9673857d8 Fix a couple of typos in various places. 2020-09-08 13:01:18 +02:00
Joris Vink 636469f555 Only reset accept_avail if we grabbed the lock.
Otherwise in certain scenarios it could mean that workers
unsuccessfully grabbed the lock, reset accept_avail and
no longer attempt to grab the lock afterwards.

This can cause a complete stall in workers processing requests.
2020-09-08 11:51:06 +02:00
Joris Vink b84c88a0e6 remove the yet wording. 2020-09-03 19:08:08 +02:00
Joris Vink 58247eec4a I don't support x86 on Linux, remove it.
Pointed out by entitled end user.
2020-09-03 19:05:43 +02:00
Joris Vink 8097d22da7 whitespace fixes 2020-08-24 10:17:53 +02:00
Joris Vink 4aa53df3b6 Make sure curl state transitions work properly. 2020-08-17 16:45:10 +02:00
Joris Vink 8b9f7a6c12 improve our asynchronous curl support.
- Remove the edge trigger io hacks we had in place.
- Use level triggered io for the libcurl fds instead.
- Batch all curl events together and process them at the end
  of our worker event loop.
2020-08-17 15:15:04 +02:00
Joris Vink eaef4b654a Only call PyMem_SetupDebugHooks() if DEBUG is 1.
We do not need the memory debug hooks in production environments.
2020-08-13 09:10:19 +02:00
Joris Vink 6b3347ae3a coro_running could be NULL, check it. 2020-08-12 13:43:38 +02:00
Joris Vink 7613a4a135 Python: Improve the kore.socket interface.
- Make sure PyBuffer_Release() is called for y* arguments.
- Make sure buffer is cleaned up for SENDTO socket ops as well.
2020-08-11 15:24:59 +02:00
Joris Vink 68d078766e Clear lockop before removing a reference from the coroutine. 2020-08-10 12:19:42 +02:00
Joris Vink 08d66e3926 set a worker its running flag to 0 if it dies. 2020-08-10 09:33:34 +02:00
Joris Vink 0b659807bf more missing syscalls on aarch64 2020-07-14 15:47:58 +02:00
Joris Vink 0268a0ae0a Wrap certain syscalls inside of an ifdef.
Makes kore with python and acme work on my pinebook pro.
2020-07-14 15:38:54 +02:00
Joris Vink bb2f0d8b52 Python: improve kore.lock when handling cancelled coroutines.
If a coroutine is killed from another coroutine and the killed coroutine
was waiting on a kore.lock() object, it would have been incorrectly
woken up again once said lock was released.

This would cause a Python exception that a generator was already
running and a crash due to the pool element already being freed.

Track the active locking operation per coroutine so we can remove
the coroutine if it is killed, fixing the problem.
2020-07-09 20:22:18 +02:00
Joris Vink 8235759bca Python: Add kore.app().
This method allows you to set a Python object and obtain it
by calling the method again without any arguments.

eg:

foo = SomeClass()

kore.app(foo)

foo = kore.app()
2020-07-05 21:47:22 +02:00
Joris Vink e38c6e5d30 Python: Several fixes for our async curl support.
- Fix the curl-extract-opt.sh generation script to work on newer
  curl releases as the header changed slightly.
- Use the correct handles when calling curl_easy_setopt() inside
  of our setopt functions exported via Python.
- Add a curl.setbody() method, allowing a body to be sent to be set.
  (eg when sending mail via SMTP).
- Regen of our python_curlopt.h from 7.71.1
2020-07-02 08:41:17 +02:00
Joris Vink 122a86013b Python: respond with 500 in case of a coroutine error.
If a coroutine throws an exception, respond with a 500
after logging the exception itself.
2020-06-30 09:57:48 +02:00
Joris Vink 2316f1016d Always prune disconnected clients at the end of the event loop. 2020-06-26 12:25:07 +02:00
Joris Vink 74432aeff7 Set netwait to 10ms if a signal is pending.
If a signal is delivered after the signal check in the worker
loop we could end up in a scenario where we wait for i/o to
start triggering it.
2020-06-16 17:29:45 +02:00
Frederic Cambus ce8290cefc Add missing test for SYS_stat, fixes the build on arm64. 2020-06-09 21:44:38 +02:00
Joris Vink 8a39d18196 work around different dirname()/basename() implementations. 2020-06-09 12:22:22 +02:00
Joris Vink 30e9b642a0 Skip ACME worker process if ACME isnt built-in. 2020-06-05 14:21:39 +02:00
Joris Vink dcb34033fa trailing whitespace 2020-05-08 22:43:12 +02:00
Joris Vink 40dddbc769 whitespace 2020-04-27 09:07:37 +02:00
Joris Vink c83f34c938 Rework http_pretty_error a tiny bit. 2020-03-04 08:36:10 +01:00
Frederic Cambus fe43ed09ac Add the http_pretty_error configuration option.
When enabled, Kore returns HTML error pages for status codes 4xx and
5xx instead of empty content.
2020-03-04 08:22:51 +01:00
Joris Vink db31f37ab0 Add a "return" configuration option.
This hooks into the existing redirection framework but allows you
to quickly deny certain paths with a 403 or other status code.

The snippet below would for example declare a filemap served from 'www'
directory but denying all access to the files under the 'data' directory:

filemap		/	www
deny		/data	403
2020-03-03 11:28:16 +01:00
Joris Vink 9e5e698e4b only count TLS enabled domains as primary_dom.
Otherwise one can run into trouble with ACME if it was enabled on
domains but the first domain in the configuration was a non TLS domain.
2020-02-21 13:58:03 +01:00
Joris Vink 82d7b58405 Add trailing byte in http_token and http_field_content. 2020-02-19 10:38:41 +01:00
Frederic Cambus b4ebee5913 Add the http_server_version configuration option.
This allows setting a custom server header from the config file, for
example to mask the version number.
2020-02-19 08:07:02 +01:00
Frederic Cambus cc6ab4f05d Allow the stat syscall in keymgr, it is used in keymgr_save_randfile(). 2020-02-13 15:10:58 +01:00
Joris Vink 4115df69f6 adjust for configuration changes 2020-02-11 11:04:10 +01:00
Frederic Cambus b24bc43051 Variable ‘c’ was set but not used so remove it, broke the build with GCC 9.2.0. 2020-02-10 15:43:46 +01:00
Joris Vink 6ba56bb8f6 adjust copyright years 2020-02-10 15:35:41 +01:00
Joris Vink 9d0aef0079 bump copyright 2020-02-10 14:47:33 +01:00
Joris Vink fa2e8ef0b6 Add support for config based redirection.
Inside the domain contexts a 'redirect' rule will allow you to redirect
a request to another URI.

Ex:

Redirect all requests with a 301 to example.com

	redirect ^/.*$ 301 https://example.com

Using capture groups

	redirect ^/account/(.*)$ 301 https://example.com/account/$1

Adding the query string in the mix

	redirect ^/(.*)$ 301 https://example.com/$1?$qs
2020-02-07 06:42:33 +01:00
Joris Vink 6072828d8f Improve BSD platform event code.
Instead of adding all listening sockets into the kqueue at platform init,
do it in the first call to kore_platform_enable_accept().

This way a worker process can still call kore_server_create() in its
kore_worker_configure() hook.
2020-01-24 19:36:32 +01:00
Joris Vink d86a10afa1 allow use udata in kore.timer() via the data kwarg. 2020-01-22 09:42:41 +01:00
Joris Vink 2d380cac3f Expose our async libcurl support to the Python api.
Kore already exposed parts of this via the kore.httpclient() method but
this commit takes it a bit further and exposes the libcurl interface
completely (including the setopt options).

tldr:

handle = kore.curl("ftp://ftp.eu.openbsd.org/pub/OpenBSD/README")
handle.setopt(kore.CURLOPT_TIMEOUT, 5)

data = await handle.run()
print("%s" % data.decode())
2020-01-18 19:43:38 +01:00
Joris Vink 6f31e14e83 sprinkle kore_quiet around 2020-01-17 22:25:52 +01:00
Joris Vink 01cc981632 Improve waiting on workers to exit take 2.
Keep track of what workers are running and account for those when things
exit. Somewhat reverts the entire last commit, that was the wrong approach.
2020-01-17 21:48:55 +01:00
Joris Vink d8ff8e2c18 Improve waiting on children to exit.
If waitpid() returns -1 check if errno is ECHILD, just mark the worker
process as exited.

This could happen if Kore starts without keymgr/acme but those would still
be accounted for.
2020-01-17 21:43:56 +01:00
Joris Vink 445163f7c5 Add support for setting an email for ACME.
Can be configured via the acme_email configuration option.

eg:

	acme_email john@example.com
2020-01-13 11:00:40 +01:00
Frederic Cambus ff40f04693 Remove forgotten debug message. 2020-01-07 21:46:19 +01:00
Joris Vink 14095a7702 Revert chunk that snuck in last commit. 2019-12-13 20:30:13 +01:00
Joris Vink 243cd4e6a0 kore_listener_init() returns KORE_RESULT_OK or KORE_RESULT_ERROR. 2019-12-13 09:14:26 +01:00
Joris Vink 1d30760aa0 use X509_NAME_ENTRY* functions directly. 2019-11-19 13:00:17 +01:00
Joris Vink ca70f9d726 TLS improvements.
These changes improve the constraint kore had with client authentication and
multiple domains.

- Add kore_x509_subject_name() which will return a C string containing
  the x509 subject name in full (in utf8).

- Log TLS errors if client authentication was turned on, will help debug
  issues with client authentication in the future.

- If SNI was present in the TLS handshake, check it against the host specified
  in the HTTP request and send a 421 in case they mismatch.

- Throw a 403 if client authentication was enabled but no client certificate
  was specified.
2019-11-19 11:09:24 +01:00
Joris Vink 283cd6da54 allow NULL pointers to cleanup/free calls. 2019-11-19 09:44:13 +01:00
Joris Vink 56c33f85d4 change client_authority to client_verify. 2019-11-18 20:30:52 +01:00
Frederic Cambus c6dbf16b65 Account for the change from 'static' to 'route' in the CLI tool as well. 2019-11-16 12:34:57 +01:00
Joris Vink f8accef3f7 allow access/accessat at all times in keymgr. 2019-11-15 09:28:33 +01:00
Joris Vink f6cd16c567 Replace static/dynamic with a single option: route
Kore will automatically detect if a route is a dynamic or static one
so there is no need for the configuration options to differ anymore.
2019-11-15 08:11:02 +01:00
Joris Vink 73757a29d5 Make dumb compilers happy. 2019-11-15 07:49:16 +01:00
Joris Vink b3b5aa37b7 Allow acme config via python api 2019-11-13 23:01:24 +01:00
Joris Vink 7c78526e82 pull in ptrace.h 2019-11-13 15:56:36 +01:00
Joris Vink 7cf0006f52 fix potential NULL dereferences.
found by clang --analyze, reminded by fahlgren@
2019-11-13 11:23:02 +01:00
Joris Vink e2930f29c1 wrap pledge stuff into an ifdef __OpenBSD__ block. 2019-11-07 08:29:38 +01:00
Joris Vink bb39643b48 small acme fixes.
- don't create the NID for the acme extension several times
- add missing pledges for openbsd keymgr (it will write+create files)
2019-11-07 07:56:13 +01:00
Joris Vink c78535aa5d Add acmev2 (RFC8555) support to Kore.
A new acme process is created that communicates with the acme servers.

This process does not hold any of your private keys (no account keys,
no domain keys etc).

Whenever the acme process requires a signed payload it will ask the keymgr
process to do the signing with the relevant keys.

This process is also sandboxed with pledge+unveil on OpenBSD and seccomp
syscall filtering on Linux.

The implementation only supports the tls-alpn-01 challenge. This means that
you do not need to open additional ports on your machine.

http-01 and dns-01 are currently not supported (no wildcard support).

A new configuration option "acme_provider" is available and can be set
to the acme server its directory. By default this will point to the
live letsencrypt environment:
    https://acme-v02.api.letsencrypt.org/directory

The acme process can be controlled via the following config options:
  - acme_root (where the acme process will chroot/chdir into).
  - acme_runas (the user the acme process will run as).

  If none are set, the values from 'root' and 'runas' are taken.

If you want to turn on acme for domains you do it as follows:

domain kore.io {
	acme yes
}

You do not need to specify certkey/certfile anymore, if they are present
still
they will be overwritten by the acme system.

The keymgr will store all certificates and keys under its root
(keymgr_root), the account key is stored as "/account-key.pem" and all
obtained certificates go under "certificates/<domain>/fullchain.pem" while
keys go under "certificates/<domain>/key.pem".

Kore will automatically renew certificates if they will expire in 7 days
or less.
2019-11-06 19:43:48 +01:00
Joris Vink b226b6ca89 Allow seccomp to work on arm64 and i386. 2019-11-05 13:12:43 +01:00
Joris Vink 68ce436fa7 expand previous commit further, check proto as well. 2019-11-04 07:23:21 +01:00
Joris Vink 0eab72f4cd Only call http_check_timeout on established clients. 2019-11-03 22:28:48 +01:00
Joris Vink 068b295427 remove error pledge, die hard. 2019-11-03 19:52:47 +01:00
Raymond Pasco 811b2eb3f0 Add dns to pledges when initializing curl
Without the dns pledge, curl can't resolve names on OpenBSD.
2019-11-03 11:47:49 +01:00
Joris Vink 8311c036d9 Add seccomp_tracing configuration option for linux.
If set to "yes" then Kore will trace its child processes and properly
notify you of seccomp violations while still allowing the syscalls.

This can be very useful when running Kore on new platforms that have
not been properly tested with seccomp, allowing me to adjust the default
policies as we move further.
2019-10-31 12:52:10 +01:00
Joris Vink 16afcb66d0 kodev MINIMAL=1 shouldn't include mime types either. 2019-10-31 09:55:14 +01:00
Joris Vink ca17e08ad9 Add MIMINAL=1 build to kodev.
If the kodev tool is built with MINIMAL=1 it will not compile in
support for creating application skeletons, only to build apps, etc.

Building with MINIMAL=1 drops the openssl linkage.
2019-10-31 09:44:47 +01:00
Joris Vink 699ba3c0fe Make sure json offset advanced upon end of object/array. 2019-10-30 10:02:51 +01:00
Joris Vink 7b5046873a Make sure we wakeup the coroutine that called proc.reap().
We actually woke up the coroutine that originally spawned the process
when we reap it, but another coroutine may have taken over the object.

This mimics how we do things for the pysock_op things.
2019-10-29 15:12:20 +01:00
Joris Vink ebee0f3752 nope, changed my mind, drop libressl 2.7.5. 2019-10-28 12:47:51 +01:00
Joris Vink d001b022a7 Cleanup ifdef mess for different OpenSSL based libs.
Now everything that has the "newer" OpenSSL API (1.1.x) is hidden
behind a KORE_OPENSSL_NEWER_API define. Tone down minimum libressl
version again to 2.7.5.
2019-10-28 12:33:39 +01:00
Joris Vink 4808365f8a Make sure things build with libressl 3.0.0 2019-10-27 21:20:47 +01:00
Joris Vink 5f03f991c9 Change kore_json_find() to operate on a kore_json_item.
This way you can call the lookup function on any JSON value that you
previously obtained (or the JSON context root).
2019-10-25 12:27:16 +02:00
Joris Vink f637d617aa Allow SECCOMP_KILL_POLICY to be overwritten at build. 2019-10-23 15:01:31 +02:00
Joris Vink da959e8275 reset curl timer if nothing is running anymore. 2019-10-23 12:38:31 +02:00
Joris Vink 890eb78fd8 Improve our new JSON api a bit.
Allow JSON to be constructed via kore_json_create_item and its
handy macro family:
	- kore_json_create_object()
	- kore_json_create_array()
	- kore_json_create_string()
	- kore_json_create_number()
	- kore_json_create_literal().

Adds kore_json_item_tobuf() to convert a JSON item into a string
representation in a kore_buf data structure.

Renames the kore_json_get* family to kore_json_find* instead.

Allows for quite clean code:

	struct kore_buf		buf;
	struct kore_json_item	*root;

	root = kore_json_create_object(NULL, NULL);
	kore_json_create_string(root, "hello", "world");
	kore_json_create_number(root, "value", 2.241);

	kore_buf_init(&buf, 128);
	kore_json_item_tobuf(root, &buf);

	kore_json_item_free(root);
	kore_buf_cleanup(&buf);
2019-10-22 23:56:47 +02:00
Joris Vink 790d020ce9 Stop a python coro from getting stuck with httpclient.
In cases where a request is immediately completed in libcurl its multi
handle and no additional i/o is happening a coro can get stuck waiting
to be run.

Prevent this by lowering netwait from KORE_WAIT_INFINITE if there
are pending python coroutines.
2019-10-22 17:06:32 +02:00
Joris Vink a119f18a23 Adjust to new kore_curl_init(). 2019-10-21 13:29:26 +02:00
Joris Vink b64ae5d111 Allow kore_curl calls to be synchronous.
Changes kore_curl_init() to take a flag parameter, much like pgsql api
in which you specify KORE_CURL_ASYNC or KORE_CURL_SYNC.

If KORE_CURL_ASYNC is specified, Kore will behave as before.
If Kore_CURL_SYNC is specified, Kore will execute the libcurl immediately
and return once it has been completed.
2019-10-21 13:26:44 +02:00
Joris Vink 22ebfae240 missing kore_free() 2019-10-20 23:55:08 +02:00
Joris Vink 00f505e3f3 simplify strtod() error checking.
we can just check if errno is ERANGE and drop d == 0 comparison.
2019-10-20 23:43:54 +02:00
Joris Vink 88330a5fcd missing kore_free() 2019-10-20 23:42:37 +02:00
Joris Vink e94cc2f3a8 Yikes, add the actual JSON parser code.. 2019-10-20 23:30:10 +02:00
Joris Vink 7da7141c21 remove FILEREF_DEBUG that sneaked in 2019-10-16 12:13:21 +02:00
Joris Vink cdc3347120 Add kore.sendmsg(object, worker=None) to the python api.
This allows you to send Python objects that can be run through pickle
to other worker processes.

If your application implements koreapp.onmsg() you will be able to receive
these objects.
2019-10-16 12:05:27 +02:00
Joris Vink ffb9fd2fc5 Align kore memory functions on 16-byte boundaries. 2019-10-15 21:33:43 +02:00
Joris Vink e90e3749a7 use Py_InitializeEx and do not install python signals. 2019-10-15 21:18:38 +02:00
Joris Vink bdc75556fe call PyErr_Clear() in python_callable(). 2019-10-15 16:03:39 +02:00
Joris Vink a1c1245ef7 don't call Py_DECREF on list in configure 2019-10-15 15:53:08 +02:00
Joris Vink 0f4d5294ad store active pid into apid so it does not overwritten. 2019-10-15 14:25:57 +02:00
Joris Vink bc33a5def4 Add kore.proc.pid, returns the PID of the proc. 2019-10-15 14:23:49 +02:00
Joris Vink ec249390b1 Allow building with python3.8 2019-10-15 10:16:53 +02:00
Joris Vink 3dcf94d1ae Add seccomp.bpf_stmt() method to Python api.
Allows a developer to create their own statements, the bpf_jmp equivalent
may follow later if I need it.
2019-10-07 13:44:31 +02:00
Joris Vink 0eb11794f5 Do not add keymgr its msg fd if not started.
Reshuffles the keymgr_active flag to keymgr.c and let it be figured out
from inside kore_server_start() instead of the worker init code.
2019-10-07 10:31:35 +02:00
Joris Vink 7209a67d47 unbreak DEBUG builds 2019-10-04 19:24:57 +02:00
Joris Vink 97523e2768 only register tls related msg callbacks if needed 2019-10-04 19:20:37 +02:00
Joris Vink 7bc1a92192 remove norwegian debug 2019-10-04 12:44:37 +02:00
Joris Vink 6c8970651c s/hook/method 2019-10-04 11:34:49 +02:00
Joris Vink b0cf42726d Do not start keymgr if no tls enabled servers are present 2019-10-04 11:29:45 +02:00
Joris Vink 11cc5d304f let kore_python_seccomp_hook() take the hook name 2019-10-04 11:28:14 +02:00
Joris Vink 8bbdaedf94 Allow configuring seccomp on Linux via the python api.
A new hook in the koreapp class is called right before seccomp
is enabled. This hook receives a Kore seccomp object which has
the following methods:

	seccomp.allow("syscall")
	seccomp.allow_arg("syscall", arg, value)
	seccomp.allow_flag("syscall", arg, flag)
	seccomp.allow_mask("syscall", arg, mask)

	seccomp.deny("syscall")
	seccomp.deny_arg("syscall", arg, value, errno=EACCES)
	seccomp.deny_flag("syscall", arg, flag, errno=EACCES)
	seccomp.deny_mask("syscall", arg, mask, errno=EACCES)

This allows you to finetune the seccomp filters for your application
from inside your koreapp.
2019-10-04 10:59:48 +02:00
Joris Vink bcf0355704 Add clock_gettime to keymgr process 2019-10-03 15:55:19 +02:00
Frederic Cambus 85981e22cc Allow the nanosleep syscall, it is used in kore_accesslog(). 2019-10-03 15:53:36 +02:00
Joris Vink 5e6a8d42cf include sys/socket.h in net.c 2019-10-03 12:19:36 +02:00
Joris Vink d0e46adfb1 kill norwegian debug 2019-09-27 20:08:16 +02:00
Joris Vink 46375303cb Allow multiple binds on new server directive. 2019-09-27 20:00:35 +02:00
Joris Vink be70118bf2 move l->tls check upwards 2019-09-27 12:33:48 +02:00
Joris Vink 46127459d9 fix BSDs after last commit 2019-09-27 12:31:17 +02:00
Joris Vink 7350131232 Allow listening of tls/notls ports at the same time.
Before kore needed to be built with NOTLS=1 to be able to do non TLS
connections. This has been like this for years.

It is time to allow non TLS listeners without having to rebuild Kore.

This commit changes your configuration format and will break existing
applications their config.

Configurations now get listener {} contexts:

listen default {
	bind 127.0.0.1 8888
}

The above will create a listener on 127.0.0.1, port 8888 that will serve
TLS (still the default).

If you want to turn off TLS on that listener, specify "tls no" in that
context.

Domains now need to be attached to a listener:

Eg:
	domain * {
		attach	default
	}

For the Python API this kills kore.bind(), and kore.bind_unix(). They are
replaced with:

	kore.listen("name", ip=None, port=None, path=None, tls=True).
2019-09-27 12:27:04 +02:00
Joris Vink 0d72f11902 make sure we can still run normal apps even with PYTHON=1 2019-09-26 20:38:02 +02:00
Joris Vink f725ca228c alter python skeleton from kodev create -p.
adds the kore.config.file setting (required a fix for -c) and the
kore.config.deployment option is set to "development".
2019-09-26 19:58:13 +02:00
Joris Vink 555856ab0a fix usage for python builds.
while here, force a module or script as a cli argument and
fix kodev run to pass the config if inside of a module.
2019-09-26 16:41:52 +02:00
Joris Vink b7163f35ce allow readlink syscall 2019-09-26 16:29:45 +02:00
Joris Vink d4ba6f3485 allow more net related syscalls for python. 2019-09-26 16:13:42 +02:00
Joris Vink 9d7ef805f0 hide rcall properly if needed 2019-09-26 16:05:01 +02:00
Joris Vink 937c39f041 Many many Python improvements.
- Kore can now fully be configured via Python code if one wants nothing to
  do with configuration files.

- Kore can now start single python files and no longer requires them to be
  inside a module directory.

- Pass all regex capture groups to the handler methods, allowing you to
  get access to them immediately.

- Change python websocket_handshake to take callable objects directly.

- Added a new deployment configuration option. If set to "dev" or
  "development" Kore will automatically foreground, no chroot / etc.
  If set to "production" Kore *will* chroot, drop privs, etc.

- Many more..

These are all backported from a project that I was working on a while
ago. I decided these should go back into mainline Kore.
2019-09-26 15:49:00 +02:00
Joris Vink 296fe7a6d4 seccomp improvements.
More BPF helper macros, more helper for granular syscall checking.
Use these throughout kore where it makes sense.

The new helpers:

- KORE_SYSCALL_DENY_ARG(name, arg, value, errno):
	Deny the system call with errno if the argument matches value.

- KORE_SYSCALL_DENY_MASK(name, arg, mask, errno):
	Deny the system call with errno if the mask argument does not match
	the exact mask given.

- KORE_SYSCALL_DENY_WITH_FLAG(name, arg, flag, errno):
	Deny the system call with errno if the argument contains the
	given flag.

The reverse also exists:

- KORE_SYSCALL_ALLOW_ARG()
- KORE_SYSCALL_ALLOW_MASK()
- KORE_SYSCALL_ALLOW_WITH_FLAG()
2019-09-26 13:51:53 +02:00
Joris Vink 4ed6136693 add 2 more missing syscalls for musl to keymgr. 2019-09-26 10:20:30 +02:00
Joris Vink 9dc12af1a4 add rt_sigprocmask for keymgr seccomp policy 2019-09-26 10:06:32 +02:00
Joris Vink a64be43ccf add writev to keymgr, needed on some platforms 2019-09-26 10:02:58 +02:00
Joris Vink c6c253305a swap sockets to use send/recv and update seccomp. 2019-09-26 09:53:51 +02:00
Joris Vink 0314521658 shuffle some stuff around 2019-09-26 09:28:12 +02:00
Joris Vink aafecb9485 Make sure filters from the hook are added first.
This allows user seccomp filters to be added before the kore ones which
means developers can override our own settings.
2019-09-26 09:22:33 +02:00
Joris Vink c1affbbd74 simplify bpf rule generation, add deny macro. 2019-09-25 23:41:43 +02:00
Joris Vink 61b8a9e90d fix tpyo 2019-09-25 16:14:58 +02:00
Joris Vink de97318a95 hide seccomp logs behind !quiet 2019-09-25 16:14:17 +02:00
Joris Vink 4bc39f19af add lstat to worker seccomp filter 2019-09-25 15:44:03 +02:00
Joris Vink eab94eda49 move libressl support to minimum 3.3.0. 2019-09-25 15:39:39 +02:00
Joris Vink 54ca865c11 add a few more syscalls for keymgr.
different platforms may do different things
2019-09-25 15:04:12 +02:00
Joris Vink 68e90507f4 properly seccomp keymgr 2019-09-25 14:41:09 +02:00
Joris Vink cd9971247c Add seccomp syscall filtering to kore.
With this commit all Kore processes (minus the parent) are running
under seccomp.

The worker processes get the bare minimum allowed syscalls while each module
like curl, pgsql, etc will add their own filters to allow what they require.

New API functions:
    int kore_seccomp_filter(const char *name, void *filter, size_t len);

    Adds a filter into the seccomp system (must be called before
    seccomp is enabled).

New helpful macro:
    define KORE_SYSCALL_ALLOW(name)

    Allow the syscall with a given name, should be used in
    a sock_filter data structure.

New hooks:
    void kore_seccomp_hook(void);

    Called before seccomp is enabled, allows developers to add their
    own BPF filters into seccomp.
2019-09-25 14:31:20 +02:00
Joris Vink d99d0b2d77 add lock.trylock() and make lock.release() sync. 2019-09-20 10:03:43 +02:00
Joris Vink c3b2a8b2a2 fix NOHTTP builds 2019-09-20 09:37:02 +02:00
Joris Vink 868b0a71a2 make coro tracing available at runtime, always.
call kore.corotrace(True) to enable it and kore.corotrace(False) to disable.
2019-09-18 10:55:13 +02:00
Joris Vink 95506204e8 Add kore.task_kill() to the python api.
Allows killing of coroutines, given their task id.

The kore.task_create() method now returns the task id for a newly
created task to the caller.

While here, change the coroutine task id to a uint32 from uint64.
There is no need for it to be 64bit. (famous last words)
2019-09-17 20:04:35 +02:00
Joris Vink c1653a5254 hide kore.coroname() behind PYTHON_CORO_TRACE. 2019-09-16 20:33:14 +02:00
Joris Vink 019006620d allow coroutines to set friendly names. 2019-09-16 20:31:25 +02:00
Joris Vink 960fabe44c s/PYTHON_CORO_DEBUG/PYTHON_CORO_TRACE 2019-09-16 20:25:34 +02:00
Joris Vink 1ee1021aba trace created/deleted. 2019-09-16 20:21:04 +02:00
Joris Vink 9bcccb9483 Add coroutine debugging.
If built with PYTHON_CORO_DEBUG in CFLAGS Kore will spew out coroutine
traces while running. These traces include the filename, function and line
number where the coroutines are waking up, running and suspended.
2019-09-16 20:11:42 +02:00
Joris Vink dbb99a56d1 move new/wokenup/suspended coros to end of lists. 2019-09-16 19:34:47 +02:00
Joris Vink 58a6b4e331 trailing space fix 2019-09-13 23:22:38 +02:00
Joris Vink 3207ce8526 pgsql improvements round 2
- kill PQsetnonblocking(), it's not what one thinks.
- keep doing the PQconsumeInput()/PQisBusy() dance until
  the former clears all read data.
2019-09-13 23:20:51 +02:00
Joris Vink f2472ba485 allow python modules to set progname. 2019-09-04 20:37:33 +02:00
Joris Vink 8e858983bf python pgsql changes.
- decouple pgsql from the HTTP request allowing it to be used in other
  contexts as well (such as a task, etc).

- change names to dbsetup() and dbquery().

eg:

result = kore.dbquery("db", "select foo from bar")
2019-09-04 19:57:28 +02:00
Joris Vink f3b7cba58c Call PQConsumeInput() again after PQisBusy().
Prevents a stall in case there is still data in the read end of the socket
but PQisBusy() told us to not fetch a result yet. In that case we end up
stalling due to epoll not giving us another EPOLLIN event due to EPOLLET.
2019-09-04 19:19:52 +02:00
Joris Vink b54b93536d Use strdup() when munging environment pointers. 2019-08-27 13:12:44 +02:00
Joris Vink c32880e12b http_argument_decode() can fail. 2019-08-02 11:34:45 +02:00
Joris Vink 0b9e174af4 http_argument_urldecode() could fail. 2019-07-20 20:35:58 +02:00
Joris Vink 0f58de36f4 Be a little less strict on url decoding. 2019-07-16 21:31:32 +02:00
Joris Vink f2e17c1384 return NULL if PyUnicode_FromString fails. 2019-07-16 21:31:19 +02:00
Joris Vink 5055f3c872 add kore.worker() to the python api.
returns the current worker number or None if on parent.
2019-06-16 19:57:48 +02:00
Joris Vink 4a64b4f07b Improve curl timeout handling.
In case libcurl instructs us to call the timeout function as soon
as possible (timeout == 0 in curl_timeout), don't try to be clever
with a timeout value of 10ms.

Instead call the timeout function once we get back in the worker
event loop. This makes things a lot snappier as we don't depend
on epoll/kqueue waiting for io for 10ms (which actually isn't 10ms...).
2019-06-13 12:59:17 +02:00
Joris Vink 574c9a7084 make sure kodev run works in python modules. 2019-06-13 11:18:10 +02:00
Joris Vink 3114f8d8d0 Improve python experience.
- If Kore is built with PYTHON=1 you can now specify the module that
  should be loaded on the command-line.

     eg: $ kore -frn myapp

- Add skeleton generation for python applications to kodev.

     eg: $ kodev create -p myapp

This should make it a whole lot easier to get started with kore python.
2019-06-12 23:35:43 +02:00
Joris Vink a46447b1f9 set hdlr_extra to NULL in pyhttp_iterobj_disconnect. 2019-06-12 21:09:57 +02:00
Joris Vink 6c18856a3e get rid of mtime in modules.
kore should always reload things when it was told to reload things.
there are use cases were a module reload is because the code itself changed.
2019-06-09 23:24:53 +02:00
Frederic Cambus bae117b68c Set req->agent to "-" if it is NULL, as do other major HTTP servers.
This avoids passing a NULL value to a format string when writing a log
entry.
2019-06-09 21:36:12 +02:00
Joris Vink d4f4e007e0 make sure prereqs are in order 2019-06-07 21:33:00 +02:00
Joris Vink 6ed3ac4658 kill debug 2019-06-07 21:25:18 +02:00
Joris Vink 3cc7d6e238 Allow kore.prerequests to be async. 2019-06-07 21:06:54 +02:00
Joris Vink 9cc58d45c1 Python HTTP improvements.
1) Add @kore.prerequest python decorator.

Using this decorator on a function will cause that function
to always be executed *before* any page handler is run.

eg:

@kore.prerequest
def _check(req):
    if req.method == kore.HTTP_METHOD_POST:
        req.populate_post()

2) Allow attributes to be set on the pyhttp object.
2019-06-05 23:45:45 +02:00
Joris Vink 89e58fa474 Improve iterator support for Python req.response().
If the connection on which we are about to send the response was
marked as disconnecting, do not go ahead and hook into the disconnect
callback (it will never be called, it is already disconnecting).

Instead just return, the connection will be removed anyway.
2019-06-05 10:35:47 +02:00
Joris Vink 93b1d621d7 Remove memleak from Python httpclient.
We grab a reference to the pyhttp_client for the client_op data structure
but never removed it. This caused the pyhttp_client object to never
be released when out of scope.
2019-06-05 10:27:20 +02:00
Joris Vink a4d18ca276 Add HTTP runlocks.
A way to serialize access to HTTP page handlers in case you are
using some asynchronous api such as pgsql or libcurl stuff.
2019-06-02 16:29:54 +02:00
Joris Vink 1686ec22e6 Some C pgsql api improvements. 2019-06-01 23:14:50 +02:00
Joris Vink ff7c85460c Wake up HTTP requests if python coros finish immediately.
python_coro_create() puts the HTTP request to sleep, but if they
finish immediately they will be removed from the list and should
properly be woken up or they are removed from the wrong list.
2019-05-30 17:15:08 +02:00
Joris Vink a8aff8b737 Improve curl error string handling.
Introduce kore_curl_strerror(), use this in kore_curl_logerror()
instead of assuming our errbuf has been populated.

Also use it in the python httpclient when throwing an exception rather
then looking at the errbuf member which may or may not be empty.
2019-05-30 14:25:04 +02:00
Joris Vink 88553cd2dd Immediately remove completed HTTP requests.
No need to wait until the next time http_process() is called, which
could result in HTTP requests backing up even though we are processing
them at a fast pace.
2019-05-29 20:30:43 +02:00
Joris Vink 07fc7a9097 Improve HTTP processing.
If netwait is INFINITE but there are requests pending reduce the
netwait back down to 100ms so we keep processing them.
2019-05-29 15:27:44 +02:00
Joris Vink c2d9f1413c Fix two concurrency issues with kore.lock().
1) If a coroutine was waken up by another releasing a lock it was waiting
on we would incorrectly remove the pylock_op when the newly awoken coroutine
hits the iternext for pylock.

2) If a coroutine attempts to grab a lock it was woken up for only to fail
we did not properly rearm the coroutine to be woken up later to try again.
2019-05-29 15:25:31 +02:00
Joris Vink 5f0153ba0e Fix unix binds on BSD families. 2019-05-28 21:44:46 +02:00
Joris Vink b4aba48fad small python improvements.
- Check for an exception when in a timer context and log it if uncaught.
- Make sure tlsverify is settable regardless of client certs being specified.
2019-05-16 21:07:42 +02:00
Joris Vink a10dfe03fe make sure user-defined headers are set for > 500.
a commit done in 2018 prevented http responses with error codes
> 500 to include any user-set headers, preventing a developer
to include things like content-type etc.

reported by Arun Babu via users@
2019-05-12 20:53:27 +02:00
Joris Vink 53f042a5b4 add stdint.h header to keymgr.c 2019-05-09 20:55:49 +02:00
Joris Vink 3299f60df4 tiny curl fixes. 2019-05-05 21:16:42 +02:00
Joris Vink 503f42074c http_timeout must be 0 when upgrading to websockets
otherwise kore will timeout an established websocket connection
after http_timeout seconds.
2019-05-05 14:47:04 +02:00
Joris Vink fe84997ce9 add option to use unix paths via kore.httpclient 2019-05-03 15:31:16 +02:00
Joris Vink 3c9a141cd0 allow an iterator to be passed to req.response().
if an iterator is passed kore will send the response with
transfer-encoding: chunked and call the iterator for every
chunk that was sent.

The iterator must return a utf-8 string.

Works wonderful with TemplateStream from jinja2.
2019-05-03 13:42:34 +02:00
Joris Vink 12fc1396c1 use / to split up name/version. 2019-04-30 20:45:56 +02:00
Joris Vink 502368a27e set user-agent in the curl component. 2019-04-30 20:39:46 +02:00
Joris Vink 403938d8e9 make native proctitle better.
count how much space is available for a mangled process title
only once, and use that as reference later.
2019-04-29 21:08:58 +02:00
Joris Vink d0a6958747 Let http_state_create() take an "onfree" callback.
This function is called when an HTTP request is being free'd,
allowing you to perform any sort of state cleanup attached
to the HTTP request.
2019-04-28 21:48:16 +02:00
Joris Vink 9ac77d0c9a make sure CURL_CSELECT_ERR is OR'd into flags. 2019-04-28 21:44:59 +02:00
Joris Vink e54886960e objs is a pointer, and use Py_XDECREF on it. 2019-04-25 23:25:19 +02:00
Joris Vink d0d0bdeb4f Improve pgsql support.
- Add kore_pgsql_query_param_fields() which allows you to pass in the
  arrays for values, lengths and formats yourself.

- Add kore_pgsql_column_binary() which will return 1 if the given column
  index contains a binary result or 0 if it contains a text result.

- Change the query call in req.pgsql() for Python to always use the
  parameterized queries.

This adds the 'params' and 'binary' keywords to the req.pgsql method.

Eg:
	result = await req.pgsql("db", "INSERT INTO foo (field) VALUES($1"),
	    params=["this is my value"])
2019-04-25 23:13:13 +02:00
Joris Vink 994f428a8d add cabundle keyword to kore.httpclient() 2019-04-24 21:09:24 +02:00
Joris Vink 6bd3d92fe2 unbreak. 2019-04-24 18:30:07 +02:00
Joris Vink a6af458cd2 add tlsverify keyword to kore.httpclient(). 2019-04-24 18:28:23 +02:00
Joris Vink 1b9ba84ab0 missing return value check. 2019-04-24 09:33:56 +02:00
Joris Vink a9683caed5 missing header 2019-04-24 00:16:51 +02:00
Joris Vink 2c88bc6120 Add asynchronous libcurl support.
This commit adds the CURL=1 build option. When enabled allows
you to schedule CURL easy handles onto the Kore event loop.

It also adds an easy to use HTTP client API that abstracts away the
settings required from libcurl to make HTTP requests.

Tied together with HTTP request state machines this means you can
write fully asynchronous HTTP client requests in an easy way.

Additionally this exposes that API to the Python code as well
allowing you do to things like:

	client = kore.httpclient("https://kore.io")
	status, body = await client.get()

Introduces 2 configuration options:
	- curl_recv_max
		Max incoming bytes for a response.

	- curl_timeout
		Timeout in seconds before a transfer is cancelled.

This API also allows you to take the CURL easy handle and send emails
with it, run FTP, etc. All asynchronously.
2019-04-24 00:15:17 +02:00
Joris Vink c89ba3daa3 check http timeouts better 2019-04-12 14:26:47 +02:00
Joris Vink 612fc034fa remove debug 2019-04-11 20:54:29 +02:00
Joris Vink aa49e181b6 Add http_[header|body]_timeout.
If the HTTP request headers or the HTTP body have not arrived before
these timeouts expire, Kore will send a 408 back to the client.
2019-04-11 20:51:49 +02:00
Joris Vink a191445f76 set body length+offset to 0 when populating data.
otherwise this isn't properly picked up by http_body_read() later
if dealing with in-memory HTTP bodies and you get inconsistent behaviour.
2019-04-02 22:26:44 +02:00
Joris Vink 5d16a7a123 make sure stdint.h is always included.
unbreaks NOTLS=1 and NOSENDFILE=1 builds on several platforms.

reported by Sam on irc, thanks.
2019-03-29 19:25:27 +01:00
Joris Vink a66d259271 kill debug line 2019-03-29 19:15:10 +01:00
Joris Vink d2aa64df5c add kore_proctitle().
manipulates the argv+environ pointers to get a sensible process title
under linux / darwin.
2019-03-29 16:24:14 +01:00
Joris Vink 92fb4974b1 only deschedule if not -1. 2019-03-27 22:15:35 +01:00
Joris Vink 39ffa047ca remove dh parameter check at configure time.
this is done when the workers startup if a domain with tls was used.
2019-03-26 21:44:44 +01:00
Joris Vink e4caac9e0c Be more clear when an invalid TLS setup is found 2019-03-26 21:36:45 +01:00
Joris Vink bf42e56c7d kill whitespace 2019-03-26 20:24:46 +01:00
Joris Vink 4ca7f29649 Add a concurrency parameter to kore.gather() 2019-03-25 10:13:52 +01:00
Joris Vink e1766e74ba always capture worker processes exiting.
even if they terminated normally.
2019-03-22 10:29:14 +01:00
Joris Vink 4238431b9e Add worker_death_policy setting.
By default kore will restart worker processes if they terminate
unexpected. However in certain scenarios you may want to bring down
an entire kore instance if a worker process fails.

By setting worker_death_policy to "terminate" the Kore server will
completely stop if a worker exits unexpected.
2019-03-22 09:49:50 +01:00
Joris Vink cd80685d9d get rid of pyko 2019-03-21 21:37:16 +01:00
Joris Vink 58c2739dee If fd is -1 in pysock_op_iternext just return None.
None in pysock signals EOF and if it was closed under our feet we should
relay that properly.
2019-03-21 14:44:41 +01:00
Joris Vink 370041656e Get rid of WORKER_LOCK_TIMEOUT.
Instead let the workers send a message on the msg channel to each
other when they have given up the accept lock and it is now available
to be grabbed.
2019-03-21 14:03:11 +01:00
Joris Vink 8b0279879a rework timers so they fire more predictably.
this change also stops python coroutines from waking up very
late after their timeout has expired.

in filerefs, don't prime the timer until we actually have something
to expire, and kill the timer when the last ref drops.
2019-03-21 10:17:08 +01:00
Joris Vink ce012e7bd5 set fd to -1 on close. 2019-03-21 10:09:24 +01:00