summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua115
1 files changed, 63 insertions, 52 deletions
diff --git a/main.lua b/main.lua
index 7d8c97d..b347410 100644
--- a/main.lua
+++ b/main.lua
@@ -1,86 +1,97 @@
local cqueues = require'cqueues'
+local config = require'config'
+local Channel = require'channel'
-local pylon_types = {
+local pylon_classes = {
irc = require'irc',
xmpp = require'xmpp',
}
-local Network = {}
-function Network.make(pylon_confs, bus_confs)
+local Wilson = {}
+function Wilson.make(config)
local self = {
pylons={},
busses={},
cq = cqueues.new(),
}
- for pylonname, conf in pairs(pylon_confs) do
- local pty = pylon_types[conf.type]
- self.pylons[pylonname] = pty.makepylon(pylonname, conf, self.cq, self)
- print("constructed pylon",pylonname,conf.type)
+ for name, pylon_conf in pairs(config.pylon) do
+ pylon_conf.name = name
+ local pylon_class = pylon_classes[pylon_conf.type]
+ assert(pylon_class, "no such pylon type "..pylon_conf.type)
+ self.pylons[name] = pylon_class.make(self, pylon_conf)
+ print("constructed pylon",name,pylon_conf.type)
end
- for busname, conf in pairs(bus_confs) do
+ for name, bus_conf in pairs(config.bus) do
local bus = {}
- for _, item in ipairs(conf) do
- table.insert(bus, {pylonname=item[1], channel=item[2]})
+ for _, item in ipairs(bus_conf) do
+ local pylon_name, channel_descriptor = item[1], item[2]
+ local pylon = self.pylons[pylon_name]
+ assert(pylon,"no such pylon named "..pylon_name)
+ table.insert(bus, Channel(pylon, channel_descriptor))
end
- self.busses[busname] = bus
+ print("constructed bus ",name,'with '..#bus_conf..' channels')
+ self.busses[name] = bus
end
- return setmetatable(self, {__index=Network})
+ return setmetatable(self, {__index=Wilson})
end
-function Network._find_bus(self, pylonname, channel)
+
+-- find bus containing given channel
+function Wilson._find_bus(self, channel)
for name, bus in pairs(self.busses) do
- for _, entry in ipairs(bus) do
- if entry.pylonname == pylonname and entry.channel == channel then
- return bus
- end
- end
+ for _, q in ipairs(bus) do if q == channel then return bus end end
end
- print("warning: unfound bus for",pylonname,channel)
+ print("warning: unfound bus for",channel)
end
-function Network.post(self, pylonname, channel, message)
- local bus = self:_find_bus(pylonname, channel)
+function Wilson.deliver(self, source_channel, message)
+ local bus = self:_find_bus(source_channel)
if bus then
- for _, dest in ipairs(bus) do
- if not (dest.pylonname == pylonname and dest.channel == channel) then
- local target_pylon = self.pylons[dest.pylonname]
- target_pylon.inbox:enqueue(dest.channel, message)
+ for _, dest_channel in ipairs(bus) do
+ if source_channel ~= dest_channel then
+ dest_channel.pylon:post(dest_channel, message)
end
end
end
end
-function Network.run(self)
+function Wilson.run(self)
for pylonname, pylon in pairs(self.pylons) do
self.cq:wrap(pylon.run, pylon)
print("now running pylon", pylonname)
end
- print(self.cq:loop())
+ print('toplevel',self.cq:loop())
end
+local config_file = io.open("wilson.ini","r")
+local conf = config.parse(config_file)
+config_file:close()
+local wilson = Wilson.make(conf)
+wilson:run()
+
-local pylon_confs = {
- xmpp_ubq323 = {
- type='xmpp',
- jid='wilson@ubq323.website',
- server='localhost',
- component='wilson.ubq323.website',
- component_secret='super_secret_wilson_password',
- resource='wilson',
- },
- irc_local = {
- type='irc',
- host='localhost',
- port=6667,
- password='mypassword',
- nodename='wilson.ubq323',
- },
-}
-local bus_confs = {
- d = {
- {'xmpp_ubq323', 'd@conference.ubq323.website'},
- {'irc_local', '#test'},
- },
-}
+-- local pylon_confs = {
+-- xmpp_ubq323 = {
+-- type='xmpp',
+-- jid='wilson@ubq323.website',
+-- server='localhost',
+-- component='wilson.ubq323.website',
+-- component_secret='super_secret_wilson_password',
+-- resource='wilson',
+-- },
+-- irc_local = {
+-- type='irc',
+-- host='localhost',
+-- port=6667,
+-- password='mypassword',
+-- nodename='wilson.ubq323',
+-- },
+-- }
+-- local bus_confs = {
+-- d = {
+-- {'xmpp_ubq323', 'd@conference.ubq323.website'},
+-- {'irc_local', '#test'},
+-- },
+-- }
-local the_network = Network.make(pylon_confs, bus_confs)
-the_network:run()
+-- local the_network = Wilson.make(pylon_confs, bus_confs)
+-- the_network:run()