Skip to content

Commit

Permalink
refactor: make backends extensible (#2)
Browse files Browse the repository at this point in the history
* refactor: add black for formatting and some half-way refactorings, not functional yet.

* refactor: use hatch

* fix: some fixes to get stuff working

* fix: get some xray functionality working

* fix: get user addition/removal/update working

* fix: xray logs

* fix: xray core restart

* fix: user usages

* feat: log user modifications
  • Loading branch information
khodedawsh authored May 17, 2024
1 parent 4450445 commit c962d16
Show file tree
Hide file tree
Showing 240 changed files with 1,067 additions and 750 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ xray-core
*config.json
bin/
pyvenv.cfg
_version.py

2 changes: 1 addition & 1 deletion marznode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from marznode.marznode import main

if __name__ == '__main__':
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
1 change: 1 addition & 0 deletions marznode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Initiate logger for marznode"""

import logging

from marznode import config
Expand Down
Empty file added marznode/backends/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions marznode/backends/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""What a vpn server should do"""

from abc import ABC, abstractmethod
from collections.abc import AsyncIterator
from typing import Any

from marznode.models import User, Inbound


class VPNBackend(ABC):
@abstractmethod
def contains_tag(self, tag: str) -> bool:
raise NotImplementedError

@abstractmethod
async def start(self) -> None:
raise NotImplementedError

@abstractmethod
async def restart(self, backend_config: Any) -> None:
raise NotImplementedError

@abstractmethod
async def add_user(self, user: User, inbound: Inbound) -> None:
raise NotImplementedError

@abstractmethod
async def remove_user(self, user: User, inbound: Inbound) -> None:
raise NotImplementedError

@abstractmethod
def get_logs(self, include_buffer: bool) -> AsyncIterator:
raise NotImplementedError

@abstractmethod
async def get_usages(self):
raise NotImplementedError
File renamed without changes.
Loading

0 comments on commit c962d16

Please sign in to comment.