1 -- Cjdns admin module for Lua
2 -- Written by Philip Horger
4 common = require 'cjdns/common'
7 UDPInterface.__index = UDPInterface
8 common.UDPInterface = UDPInterface
10 function UDPInterface.new(ai, config, ptype)
13 config = config or ai.config,
17 return setmetatable(properties, UDPInterface)
20 function UDPInterface:call(name, args)
21 local func = self[name .. "_" .. self.ptype]
22 return func(self, unpack(args))
25 function UDPInterface:newBind(...)
26 return self:call("newBind", arg)
29 function UDPInterface:beginConnection(...)
30 return self:call("beginConnection", arg)
33 function UDPInterface:newBind_ai(address)
34 local response, err = self.ai:auth({
35 q = "UDPInterface_new",
40 elseif response.error ~= "none" then
41 return nil, response.error
42 elseif response.interfaceNumber then
43 return response.interfaceNumber
45 return nil, "bad response format"
49 function UDPInterface:newBind_config(address)
50 local udpif = self.config.contents.interfaces.UDPInterface
51 local new_interface = {
55 table.insert(udpif, new_interface)
56 return (#udpif - 1), new_interface
59 function UDPInterface:newBind_perm(...)
61 self:newBind_config(unpack(arg)),
62 self:newBind_ai(unpack(arg))
65 function UDPInterface:beginConnection_ai(pubkey, addr, password, interface)
67 q = "UDPInterface_beginConnection",
73 request.interfaceNumber = interface
76 local response, err = self.ai:auth(request)
79 elseif response.error == "none" then
80 -- Unfortunately, no real success indicator either.
83 return nil, response.error
87 function UDPInterface:beginConnection_config(pubkey, addr, password, interface)
88 local udpif = self.config.contents.interfaces.UDPInterface
89 local connections = udpif[(interface or 0) + 1].connectTo
94 connections[addr] = this_conn
95 return this_conn -- allows adding metadata fields afterwards
98 function UDPInterface:beginConnection_perm(...)
100 self:beginConnection_config(unpack(arg)),
101 self:beginConnection_ai(unpack(arg))