~jan-kneschke/mysql-proxy/routing

« back to all changes in this revision

Viewing changes to examples/tutorial-routing.lua

  • Committer: jan at mysql
  • Date: 2009-02-17 19:56:25 UTC
  • Revision ID: jan@mysql.com-20090217195625-gahjld3rhzv2ns0z
added a directly mapped routing example

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
---
 
2
-- print the socket information to all IP based routing
 
3
--
 
4
-- * setup one virtual IP per backend server
 
5
-- * let the proxy to all those IPs
 
6
-- * create a lua-table that maps a "client.dst.name" to a backend
 
7
 
 
8
---
 
9
-- print a address 
 
10
--
 
11
function address_print(prefix, address)
 
12
        print(("%s: %s (type = %d, address = %s, port = %d"):format(prefix,
 
13
                address.name or "nil",
 
14
                address.type or -1,
 
15
                address.address or "nil",
 
16
                address.port or -1)) -- unix-sockets don't have a port
 
17
end
 
18
 
 
19
---
 
20
-- print the address of the client side
 
21
--
 
22
function connect_server()
 
23
        address_print("client src", proxy.connection.client.src)
 
24
        address_print("client dst", proxy.connection.client.dst)
 
25
end
 
26
 
 
27
---
 
28
-- print the address of the connected side and trigger a close of the connection
 
29
--
 
30
function read_handshake()
 
31
        address_print("server src", proxy.connection.server.src)
 
32
        address_print("server dst", proxy.connection.server.dst)
 
33
 
 
34
        -- tell the client the server denies us
 
35
        proxy.response = {
 
36
                type = proxy.MYSQLD_PACKET_ERR,
 
37
                errmsg = "done"
 
38
        }
 
39
 
 
40
        return proxy.PROXY_SEND_RESULT
 
41
end
 
42