Commit Graph

66 Commits

Author SHA1 Message Date
Joris Vink 064f2095b0 Update message framework with src/dst for workers.
One can now send messages to specific workers and
receiving workers can see the origin of the messages.
2015-07-06 21:08:36 +02:00
Joris Vink d8508f4a7b Add the actual task changes for last commit. 2015-07-01 11:03:54 +02:00
Joris Vink cf94a53be7 Add user callbacks for task activity.
Allows one to bind a callback to a Kore task which is called
everytime activity happens on the task channel.

Add an example as well on how this works.

Inspired by issue #68.
2015-07-01 11:01:23 +02:00
Joris Vink a64808c6b0 Improvements to our message framework.
Change the callback prototypes to:
	void callback(struct kore_msg *msg, const void *data);

This allows the callbacks to receive the full kore_msg data structure
as sent over the wire (including length and id). Useful for future
additions to the kore_msg structure (such as worker origin).

Several other improvements:
	* Accesslog now uses the msg framework as well.
	* Websocket WEBSOCKET_BROADCAST_GLOBAL now works.

Small websocket improvement in this commit:
	* Build the frame to be sent only once when broadcasting
	 instead of per connection we are broadcasting towards.
2015-06-23 18:17:14 +02:00
Joris Vink e9832b4416 Remove dh2048.pem from messaging example. 2015-06-22 21:22:24 +02:00
Joris Vink 49ca95f390 Add our messaging framework.
With this framework apps can now send messages between worker processes.

A new API function exists:
	int kore_msg_register(u_int8_t id, void (*cb)(const void *, u_int32_t);

This API call allows your app to register a new message callback for a given ID.

You can then send messages on this ID to other workers using:
	void kore_msg_send(u_int8_t id, void *data, u_int32_t length);

This framework will interally be used for a few things such as allowing
websocket data to broadcasted between all workers, adding unified caching
and hopefully eventually moving the access log to this as well.

Some internals have changed with this commit:
	* worker_clients has been called connections.
	* the parent now initializes the net, and event subsystems.
	* kore_worker_websocket_broadcast() is dead.
2015-06-22 21:13:32 +02:00
Joris Vink 1d604643b5 Add task_threads configuration option.
Before Kore would spawn a task thread per task started
if none were available. This was an obvious bad idiom
but never really hit me hard until now.

Kore will now only spawn as many task threads as configured
by "task_threads" and queue up any newly started tasks ontop
of already running threads if the limit was hit.
2015-06-04 10:29:22 +02:00
Joris Vink 428818c76b Correct the module its init() function. 2015-05-28 19:58:06 +02:00
Pascal Borreli 4e9d9968ac Fixed typos 2015-05-17 02:51:46 +01:00
Joris Vink 3ee07cfbfe Add SSE (Server Side Events) example. 2015-05-15 19:23:26 +02:00
Joris Vink b0947b73d9 Let modules decide if they want to be reloaded.
At times it seems relevant that worker their modules should not
be reloaded when receiving a SIGHUP. Developers can now control
this by returning anything else but KORE_RESULT_OK from their
initialization methods.

The parent module will always be reloaded.
2015-05-07 13:03:10 +02:00
Joris Vink 384bc8fdd6 Default to only TLSv1.2 from now on.
Add configuration setting tls_version to specify if you
either want TLSv1.2 or TLSv1.0 or both.

The configuration options ssl_cipher and ssl_dhparam
have changed name to tls_cipher and tls_dhparam. There is
no fallback so you might have to update your configs.
2015-05-06 10:59:43 +02:00
Joris Vink 25578d9428 Pass the proper size to http_state_run(). 2015-05-06 10:18:25 +02:00
Joris Vink 81c3325677 Style changes. 2015-04-07 13:11:31 +02:00
Joris Vink ec9ea6df36 Update README.md for cpp example. 2015-04-07 13:10:28 +02:00
Geenz 93fe8e6b42 Update Readmes 2015-04-01 21:39:40 -04:00
Geenz 5af3411513 Code style cleanup in C++ example. 2015-04-01 09:35:05 -04:00
Geenz 4c07491db6 Add license headers to C++ example. 2015-04-01 08:37:02 -04:00
Geenz 0da755a9fb Add C++ example. 2015-04-01 07:59:32 -04:00
Joris Vink b234b7ed65 Add HTTP_REQUEST_RETAIN_EXTRA flag to http_request
Signals Kore to not free any pointer set in req->hdlr_extra.
Useful in certain scenarios where you have data per request
bound to something in memory but do not want to lose it when
the request is freed by Kore.

Set this flag before your handler returns.
2015-03-27 23:23:21 +01:00
Joris Vink be96a93f9e Add missing ssl_dhparam to all example configs. 2015-02-06 09:02:29 +01:00
Joris Vink 1a680d8d09 Remove lingering diff file 2014-11-24 11:09:19 +01:00
Joris Vink f867882f43 Add websocket support to Kore.
Introduces a few new api functions:

- kore_websocket_handshake(struct http_request *):
	Performs the handshake on an HTTP request (coming from page handler)

- kore_websocket_send(struct connection *, u_int8_t, void *, size_t):
	Sends data to a websocket connection.

- kore_websocket_broadcast(struct connection *, u_int8_t, void *, size_t, int):
	Broadcast the given websocket op and data to all connected
	websocket clients on the worker. Note that as of right now
	the WEBSOCKET_BROADCAST_GLOBAL scope option does not work
	yet and messages broadcasted will be restricted to workers
	only.

- kore_worker_websocket_broadcast(struct connection *, void *, void *):
	Backend function used by kore_websocket_broadcast().
	Could prove useful for developers to have access to.

A simple example is given under examples/websocket.

Known issues:
	Kore does not support PING or CONT frames just yet.
2014-11-24 11:08:34 +01:00
Joris Vink ac4222e929 Proper use of kore_strtonum64(). 2014-11-24 10:39:38 +01:00
Joris Vink a4d50d3ddf Remove the my_callback example. Deprecated. 2014-10-31 10:14:47 +01:00
Joris Vink b1797231cc Properly error out in HTML5 video streaming. 2014-10-31 10:13:45 +01:00
Joris Vink 6de0f8568a Rework net, worker and some http internals.
- The net code no longer has a recv_queue, instead reuse same recv buffer.
- Introduce net_recv_reset() to reset the recv buffer when needed.
- Have the workers spread the load better between them by slightly
  delaying their next accept lock and giving them an accept treshold
  so they don't go ahead and keep accepting connections if they end
  up winning the race constantly between the workers.
- The kore_worker_acceptlock_release() is no longer available.

- Prepopulate the HTTP server response header that is added to each
  response in both normal HTTP and SPDY modes.
- The path and host members of http_request are now allocated on the heap.

These changes overall result better performance on a multicore machine,
especially the worker load changes shine through.
2014-10-22 21:16:49 +02:00
Joris Vink 0e8bdf38c4 Indenting police 2014-10-22 20:50:32 +02:00
Joris Vink 0d17d2228c Bring ktunnel example client in line with reality 2014-10-22 19:00:48 +02:00
Joris Vink ffe94ff585 KORE_LDFLAGS is no more. 2014-10-22 18:48:43 +02:00
Joris Vink b9445e84ca Use the right ssl_ctx 2014-10-22 18:44:31 +02:00
Joris Vink 81bc889abc Make ktunnel example tls1.2 only 2014-10-22 08:36:50 +02:00
Joris Vink a603b77e24 Add PUT/DELETE/HEAD methods (finally).
This commit renames certain POST centric variable and configuration
naming to the correct HTTP body stuff.

API changes include http_postbody_text() and http_postbody_bytes() to
have become http_body_text() and http_body_bytes().

The developer is still responsible for validating the method their
page handler is called with. Hopefully this becomes a configuration
option soon enough.
2014-10-08 11:03:14 +02:00
Joris Vink 626206f0d8 Set idle_timer.length in ktunnel to a high number.
This makes my tunnels not timeout every 20 seconds, much nicer.
2014-09-29 14:47:01 +02:00
Joris Vink 3b09683f5c Add kore_pgsql_query_params().
This function uses PQsendQueryParams() instead of the normal PQsendQuery()
allowing you to pass binary data in a cleaner fashion.

A basic call would look something like:

char *mydata = "Hello";
size_t mydata_len = strlen(mydata);

kore_pgsql_query_params(&pgsql, req,
    "INSERT INTO foo VALUES($1::text)", KORE_PGSQL_FORMAT_TEXT, 1
    mydata, mydata_len, KORE_PGSQL_FORMAT_TEXT);

kore_pgsql_query_params() is variadic, allowing you to pass any
count of parameters where each parameter has the following:
	data pointer, data length, type of parameter.
2014-09-28 21:39:16 +02:00
Joris Vink e3417dea16 Remove the pgsql simple layer again.
I rather keep the old idioms instead of adding more complex things
on top of the async ones. Especially since the simple layer would
interfear with existing http state machines from your handler.
2014-09-19 15:53:22 +02:00
Joris Vink eef40bf2dd add a .gitignore here 2014-09-19 14:51:14 +02:00
Joris Vink c4c60e1960 Oops, make sure the new simple api can handle > 1 request without borking. 2014-09-19 14:49:12 +02:00
Joris Vink 8e9c3da764 Add a new "simple query" layer to our pgsql api.
This simple query allows you to ditch rolling your own
state machine for handling async pgsql states and instead
asks you to provide 3 functions:
	- init
	- results
	- done

You can see the different in complexity in the pgsql example,
which now contains a pgsql_simple.c holding the same asynchronous
query as in pgsql.c but using the simple pgsql api.

You can of course still roll your own in case you want more control.
2014-09-19 12:32:49 +02:00
Joris Vink 0e11edefb5 s/HTTP_STATUS_RETRY/HTTP_STATE_RETRY 2014-09-19 11:16:56 +02:00
Joris Vink 8982a7b3c9 Disable timeouts for ktunnel 2014-09-18 10:30:59 +02:00
Joris Vink 34d146fc01 Fix ktunnel compilation under BSDs 2014-09-18 09:52:48 +02:00
Joris Vink c5f00d3443 Add KTunnel example, an anything-over-HTTPS tunnel using Kore. 2014-09-17 08:53:13 +02:00
Joris Vink 6e6b042388 Add KORE_PGSQL_STATE_WAIT to our example 2014-08-15 12:39:31 +02:00
Joris Vink 8565b47800 Attach tasks/pgsqls to http_requests once more.
This way if an http request is removed while tasks or
pgsqls are still active they are free'd out and cancelled
properly.
2014-08-14 22:05:34 +02:00
Joris Vink 0b3c918ba6 Properly check for connection trouble in the pgsql example 2014-08-14 15:13:47 +02:00
Joris Vink f93747828c Major pgsql rework.
Gone is the ugly KORE_PGSQL macro that hid an overly complex
state machine for the pgsql api.
Gone is the pgsql array that was attached to http_requests.
Gone are the callback hacks inside the pgsql api.

Instead, I strongly encourage people to use the new state machine
api Kore offers to properly deal with asynchronous queries.

The pgsql example in examples/pgsql has been updated to reflect
these changes.
2014-08-14 14:34:23 +02:00
Joris Vink e0cdc31c73 Take away the reference to the video if we're not streaming 2014-08-12 09:43:19 +02:00
Joris Vink 7349fab13f Sprinkle kore_snprintf() where appropriate. 2014-08-11 11:02:30 +02:00
Joris Vink 70d9df8896 s/id/user 2014-08-11 11:01:59 +02:00