motivation
I spent 2 days redeveloping a v2ray config generator to fulfill my increasing demand for proxy server configuration.
Currently, I have more than 20 different simple configurations (i.e. one-level proxy) for more than 10 servers. Despite a lot of them being just servers of different domains to balance the load across CDN, managing all of them with complex proxy chains is a headache. A typical proxy chain configuration can reach 500+ lines of JSON, which is quite some work to write even one. Moreover, several of my friends are using the services too, which makes the configuration even harder.
I wrote a super long python script to work with a sqlite3 database one year ago trying to automate the process. It worked well until the demand for proxy chains arises. Due to the lack of knowledge and foresight, I use raw SQL to extract information into python dictionaries. This works at a simple level, but the model information is lost during the process. The work became exponentially more difficult as the requirement became complex.
With all the knowledge acquired last year, I re-implement the program with python and sqlite3, again. But this time I use sqlalchamy
and jsonpickle
so that I can model the configuration instead of using just dictionaries. It turned out that such a method facilitates my development to a great extent.
I also rebuild the database model. The complete database structure is shown below.
service.chain
and virtual_server.chain
actually depends on address_group
, server
, reverse_server
, and virtual_server
. However, these information are stored in JSON so can not be seen from the database structure.
At this stage, I only implement the config class of my requirement so a lot of functions of v2ray are neglected, thus not ready to be published as a public library.