Skip to content
Snippets Groups Projects
Commit 0f401f9e authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

Merge remote-tracking branch 'origin/master'

parents b2bae6fe 38f08aeb
No related branches found
No related tags found
No related merge requests found
......@@ -653,6 +653,7 @@ iproto_process(struct iproto_request *ireq)
if (unlikely(! evio_is_active(&con->output)))
return;
ireq->session->sync = ireq->header.sync;
struct obuf_svp svp = obuf_create_svp(out);
try {
switch (ireq->header.type) {
......
......@@ -60,6 +60,18 @@ lbox_session_id(struct lua_State *L)
return 1;
}
/**
* Return the id of currently executed request.
* Many requests share the same session so this is only
* valid at session start. 0 for non-iproto sessions.
*/
static int
lbox_session_sync(struct lua_State *L)
{
lua_pushnumber(L, current_session()->sync);
return 1;
}
/**
* Session user id.
* Note: effective user id (current_user()->uid)
......@@ -249,6 +261,7 @@ box_lua_session_init(struct lua_State *L)
{
static const struct luaL_reg sessionlib[] = {
{"id", lbox_session_id},
{"sync", lbox_session_sync},
{"uid", lbox_session_uid},
{"user", lbox_session_user},
{"su", lbox_session_su},
......
......@@ -76,6 +76,7 @@ session_create(int fd, uint64_t cookie)
session->id = sid_max();
session->fd = fd;
session->cookie = cookie;
session->sync = 0;
/* For on_connect triggers. */
credentials_init(&session->credentials, guest_user);
if (fd >= 0)
......
......@@ -48,10 +48,24 @@ enum { SESSION_SEED_SIZE = 32, SESSION_DELIM_SIZE = 16 };
struct session {
/** Session id. */
uint32_t id;
/** File descriptor - socket of the connected peer. */
/** File descriptor - socket of the connected peer.
* Only if the session has a peer.
*/
int fd;
/** Peer cookie - description of the peer. */
/**
* Peer cookie - description of the peer.
* Only if the session has a peer.
*/
uint64_t cookie;
/**
* For iproto requests, we set this field
* to the value of packet sync. Since the
* session may be reused between many requests,
* the value is true only at the beginning
* of the request, and gets distorted after
* the first yield.
*/
uint64_t sync;
/** Authentication salt. */
char salt[SESSION_SEED_SIZE];
/** Cached user id and global grants */
......
......@@ -193,6 +193,10 @@ a:call('dostring', 'return space:get{session.id()}[1] == session.id()')[1][1]
---
- true
...
a:eval('return session.sync() ~= 0')
---
- true
...
a:close()
---
...
......@@ -218,6 +222,10 @@ session.user()
---
- admin
...
session.sync()
---
- 0
...
fiber = nil
---
...
......
......@@ -75,6 +75,7 @@ session.on_disconnect(audit_disconnect)
box.schema.user.grant('guest', 'read,write,execute', 'universe')
a = net.box:new(LISTEN.host, LISTEN.service)
a:call('dostring', 'return space:get{session.id()}[1] == session.id()')[1][1]
a:eval('return session.sync() ~= 0')
a:close()
-- cleanup
......@@ -86,6 +87,7 @@ space:drop()
session.uid()
session.user()
session.sync()
fiber = nil
session = nil
box.schema.user.revoke('guest', 'read,write,execute', 'universe')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment