Commit Graph

161 Commits

Author SHA1 Message Date
Joris Vink 3b4574d791 Rework pysocket async/await.
Attach the events directly to the pysocket data structure instead of
one event per pysocket_op.

Makes the code easier, gives us a good performance boost and reduces
the number of system calls required when doing an await on a socket.
2019-03-13 11:07:15 +01:00
Joris Vink 1ebd82969c Add timeout support to proc.recv() 2019-02-26 15:22:55 +01:00
Joris Vink f4cd70956b Add an optional timeout to socketop.recv(). 2019-02-25 10:35:00 +01:00
Joris Vink 1e7ccc2adf remove stale python example. 2019-02-25 10:00:59 +01:00
Joris Vink 4f1acf7060 more intmax_t 2018-11-29 21:25:20 +01:00
Joris Vink 400521073c better format string 2018-11-29 21:24:08 +01:00
Joris Vink 418c08166a use releng things 2018-11-29 21:13:43 +01:00
Joris Vink ed7b1019fc add /usr/local/include 2018-11-29 21:13:19 +01:00
Joris Vink fe52e3f4e0 update comment 2018-11-29 21:04:49 +01:00
Joris Vink 59ce048ce3 add a Makefile to build all examples. 2018-11-29 21:04:14 +01:00
Joris Vink ccaab50410 add /usr/local/lib to tasks example. 2018-11-29 21:03:22 +01:00
Joris Vink 5da99c8860 make sse example great again 2018-11-29 21:01:08 +01:00
Joris Vink b163d849a6 remove ktunnel example, its too old. 2018-11-29 20:45:26 +01:00
Joris Vink 6d78ae04b4 Add async socket example. 2018-11-23 22:34:09 +01:00
Joris Vink a030a6fd38 update README 2018-11-22 15:24:08 +01:00
Joris Vink c74c1f781d Add python-async example. 2018-11-22 15:23:44 +01:00
Joris Vink 6080bb1c35 echo server example in Python with new async/await. 2018-10-15 20:37:51 +02:00
Joris Vink c463ecb3cb Changes to the event loop inside of Kore.
Now anyone can schedule events and get a callback to work as long
as the user data structure that is added for the event begins
with a kore_event data structure.

All event state is now kept in that kore_event structure and renamed
CONN_[READ|WRITE]_POSSIBLE to KORE_EVENT_[READ|WRITE].
2018-10-09 19:34:40 +02:00
Joris Vink cffb7ec379 Allow on-the-fly reloading of certificates/keys.
This commit introduces the ability for the keymgr process
to reload the certificates/keys for domains when receiving
a SIGUSR1 signal.

The keymgr receives 2 new configuration options:
	- keymgr_root_path
		The root path where the keymgr will live.
		If -n is not specified when the application starts the
		keymgr process will chroot into here.

	- keymgr_runas_user
		The user the keymgr will drop privileges towards if
		-r was not specified.

All certfile and certkey configuration options are now relative to the
keymgr_root_path configuration setting.

The keymgr process will now also load the certificate for the domain
(rather then the workers) and submit these to the worker processes so
they can be reloaded when required.

Worker processes will refuse connections until the TLS configuration
for a given domain is completed (aka: the workers receive the certificate
for that domain).

Other changes:
	- client_certificates renamed to client_verify.
	- the chroot configuration option is now called root.
	- kore is a little more verbose if privsep options are missing.
	- filemaps are now relative to the root configuration option.
2018-07-11 09:44:29 +02:00
Joris Vink 3dfad1b7d6 remove unneeded include. 2018-05-04 15:56:56 +02:00
Joris Vink 439a3b36f0 Add kore_strtodouble().
Use it for http_argument_get_float() and http_argument_get_double().
2018-05-04 15:55:35 +02:00
Joris Vink b7669f49f7 typo 2018-05-03 21:40:50 +02:00
Joris Vink 43a0aef29f prefix HTTP defines when exporting them to python. 2018-04-10 14:35:52 +02:00
Joris Vink dd2dff2318 Rework HTTP and worker processes.
The HTTP layer used to make a copy of each incoming header and its
value for a request. Stop doing that and make HTTP headers zero-copy
all across the board.

This change comes with some api function changes, notably the
http_request_header() function which now takes a const char ** rather
than a char ** out pointer.

This commit also constifies several members of http_request, beware.

Additional rework how the worker processes deal with the accept lock.

Before:
	if a worker held the accept lock and it accepted a new connection
	it would release the lock for others and back off for 500ms before
	attempting to grab the lock again.

	This approach worked but under high load this starts becoming obvious.

Now:
	- workers not holding the accept lock and not having any connections
	  will wait less long before returning from kore_platform_event_wait().

	- workers not holding the accept lock will no longer blindly wait
	  an arbitrary amount in kore_platform_event_wait() but will look
	  at how long until the next lock grab is and base their timeout
	  on that.

	- if a worker its next_lock timeout is up and failed to grab the
	  lock it will try again in half the time again.

	- the worker process holding the lock will when releasing the lock
	  double check if it still has space for newer connections, if it does
	  it will keep the lock until it is full. This prevents the lock from
	  bouncing between several non busy worker processes all the time.

Additional fixes:

- Reduce the number of times we check the timeout list, only do it twice
  per second rather then every event tick.
- Fix solo worker count for TLS (we actually hold two processes, not one).
- Make sure we don't accidentally miscalculate the idle time causing new
  connections under heavy load to instantly drop.
- Swap from gettimeofday() to clock_gettime() now that MacOS caught up.
2018-02-14 13:48:49 +01:00
Joris Vink 548348f553 2018 2018-01-20 22:51:06 +01:00
Joris Vink b95b623e72 Allow param blocks to be marked as "querystring"
Before params get would mean querystring and anything else
would just count toward a www-encoded body.

Now you can prefix the params block with "qs" indicating that
those configured parameters are allowed to occur in the query
string regardless of the method used.

This means you can do something like:

params qs:post /uri {
	...
}

to specify what the allowed parameters are in the querystring for
a POST request towards /uri.

inspired by and properly fixes #205.
2018-01-16 18:47:50 +01:00
Joris Vink fcc044af87 change all domain directives to * in examples. 2017-09-19 15:16:02 +02:00
Joris Vink 92b4225814 add memory tag example 2017-08-30 11:50:02 +02:00
bhesmans a2d78179a4 Small fix in video stream example (#195) 2017-06-25 11:46:32 +02:00
Joris Vink 19b7f75b90 change up a comment that is wrong. 2017-06-01 10:10:54 +02:00
Joris Vink a3ed3bf7eb Convert pgsql-sync example after pgsql changes.
Only check if we bound something if we're asynchronous.
2017-03-24 13:00:05 +01:00
Joris Vink 59f7e85f45 Decouple pgsql from the http layer.
When the pgsql layer was introduced it was tightly coupled with the
http layer in order to make async work fluently.

The time has come to split these up and follow the same method we
used for tasks, allowing either http requests to be tied to a pgsql
data structure or a simple callback function.

This also reworks the internal queueing of pgsql requests until
connections to the db are available again.

The following API functions were changes:
	- kore_pgsql_query_init() -> kore_pgsql_setup()
		no longer takes an http_request parameter.
	- NEW kore_pgsql_init()
		must be called before operating on an kore_pgsql structure.
	- NEW kore_pgsql_bind_request()
		binds an http_request to a kore_pgsql data structure.
	- NEW kore_pgsql_bind_callback()
		binds a callback to a kore_pgsql data structure.

With all of this you can now build kore with PGSQL=1 NOHTTP=1.

The pgsql/ example has been updated to reflect these changes and
new features.
2017-03-24 12:53:07 +01:00
Joris Vink 3b5d4a2b03 update example 2017-03-13 13:31:36 +01:00
Joris Vink 3ae9bb7ae9 change type of maxage. 2017-03-10 14:36:51 +01:00
Joris Vink 4db51d7846 screw it, rework interface for cookies.
The only reason you would want to directly modify the cookie
after creating it should be to unset the HTTPONLY or SECURE flags
if that is what you *really* want to do.

Change http_response_cookie() to take all required parameters instead
of having to marshall those in yourself after.

Now you set a sane default cookie in one shot:

http_response_cookie(req, "key", "value", "/", 0, -1, NULL);

Which would create a session cookie key=value for / under the current domain.
2017-03-10 14:31:08 +01:00
Joris Vink 3d24b65268 Change default http_cookie behaviour.
We now default to httponly & secure for newly created cookies.

This should've been the default all along.

The http_response_cookie() no longer returns a pointer to http_cookie
but rather takes it as a parameter and will populate the pointer with
the newly created http_cookie if not NULL.

Additionally http_response_cookie() automatically sets the domain
based on the http_request passed into the function.
2017-03-10 14:20:40 +01:00
Joris Vink edd7a10773 move static assets to use asset_serve_* in generic.
note that certain browsers change their caching behaviour when you
are connecting over TLS using self-signed certificates.

reminded by #179
2017-03-08 10:20:53 +01:00
Joris Vink 175b2e2c9b kore flavor -> kodev flavor 2017-03-06 23:18:16 +01:00
Joris Vink f1d33ab91b kore -> kodev where appropriate 2017-03-06 11:00:53 +01:00
Joris Vink 3e84502235 Adjust examples after recent changes.
- New kodev tool generates config with server.pem/key.pem.
- Use proper formats for kore_log().
- Update to new websocket api.
2017-02-25 17:02:39 -08:00
Joris Vink e9b4f966c2 expose new cookie stuff to python.
req.populate_cookies()
value = req.cookie("name")
2017-02-07 22:54:42 +01:00
Joris Vink 7c78dea211 more cookie example improvements.
- remove unneed headers.
- rename local to avoid shadowing.
2017-02-07 22:12:56 +01:00
Joris Vink 4e556dbd8f rename example cookies source file. 2017-02-07 22:06:31 +01:00
Joris Vink 36e99072f3 cookie example improvements. 2017-02-07 22:04:00 +01:00
Stanislav Yudin f4ac8c2955 Cookies and arguments parsing improvements (#166)
Add new cookie API for handling of cookies.
2017-02-07 21:49:10 +01:00
Joris Vink 21bf7f9583 rework base example a bit. 2017-02-06 12:21:40 +01:00
Joris Vink 9f3046bae7 add README 2017-02-06 11:52:24 +01:00
Joris Vink 0bf36b763a add new python-pgsql example 2017-02-06 11:51:49 +01:00
Joris Vink d3f84db4b8 small fixes. 2017-02-01 21:36:53 +01:00
Joris Vink 7fb47da586 add http_file example to python example. 2017-02-01 21:35:44 +01:00