Changeset 612 in code


Ignore:
Timestamp:
Oct 7, 2021, 6:43:10 PM (4 years ago)
Author:
contact
Message:

Add max-user-networks config option

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/soju/main.go

    r592 r612  
    8989        srv.HTTPOrigins = cfg.HTTPOrigins
    9090        srv.AcceptProxyIPs = cfg.AcceptProxyIPs
     91        srv.MaxUserNetworks = cfg.MaxUserNetworks
    9192        srv.Debug = debug
    9293
  • trunk/config/config.go

    r507 r612  
    55        "net"
    66        "os"
     7        "strconv"
    78
    89        "git.sr.ht/~emersion/go-scfg"
     
    3738
    3839type Server struct {
    39         Listen         []string
    40         Hostname       string
    41         TLS            *TLS
    42         SQLDriver      string
    43         SQLSource      string
    44         LogPath        string
     40        Listen   []string
     41        Hostname string
     42        TLS      *TLS
     43
     44        SQLDriver string
     45        SQLSource string
     46        LogPath   string
     47
    4548        HTTPOrigins    []string
    4649        AcceptProxyIPs IPSet
     50
     51        MaxUserNetworks int
    4752}
    4853
     
    5358        }
    5459        return &Server{
    55                 Hostname:  hostname,
    56                 SQLDriver: "sqlite3",
    57                 SQLSource: "soju.db",
     60                Hostname:        hostname,
     61                SQLDriver:       "sqlite3",
     62                SQLSource:       "soju.db",
     63                MaxUserNetworks: -1,
    5864        }
    5965}
     
    114120                                srv.AcceptProxyIPs = append(srv.AcceptProxyIPs, n)
    115121                        }
     122                case "max-user-networks":
     123                        var max string
     124                        if err := d.ParseParams(&max); err != nil {
     125                                return nil, err
     126                        }
     127                        var err error
     128                        if srv.MaxUserNetworks, err = strconv.Atoi(max); err != nil {
     129                                return nil, fmt.Errorf("directive %q: %v", d.Name, err)
     130                        }
    116131                default:
    117132                        return nil, fmt.Errorf("unknown directive %q", d.Name)
  • trunk/doc/soju.1.scd

    r611 r612  
    130130        By default, all IPs are rejected.
    131131
     132*max-user-networks* <limit>
     133        Maximum number of networks per user. By default, there is no limit.
     134
    132135# IRC SERVICE
    133136
  • trunk/server.go

    r605 r612  
    4747
    4848type Server struct {
    49         Hostname       string
    50         Logger         Logger
    51         HistoryLimit   int
    52         LogPath        string
    53         Debug          bool
    54         HTTPOrigins    []string
    55         AcceptProxyIPs config.IPSet
    56         Identd         *Identd // can be nil
     49        Hostname        string
     50        Logger          Logger
     51        HistoryLimit    int
     52        LogPath         string
     53        Debug           bool
     54        HTTPOrigins     []string
     55        AcceptProxyIPs  config.IPSet
     56        MaxUserNetworks int
     57        Identd          *Identd // can be nil
    5758
    5859        db        Database
     
    6768func NewServer(db Database) *Server {
    6869        return &Server{
    69                 Logger:       log.New(log.Writer(), "", log.LstdFlags),
    70                 HistoryLimit: 1000,
    71                 db:           db,
    72                 listeners:    make(map[net.Listener]struct{}),
    73                 users:        make(map[string]*user),
     70                Logger:          log.New(log.Writer(), "", log.LstdFlags),
     71                HistoryLimit:    1000,
     72                MaxUserNetworks: -1,
     73                db:              db,
     74                listeners:       make(map[net.Listener]struct{}),
     75                users:           make(map[string]*user),
    7476        }
    7577}
  • trunk/user.go

    r583 r612  
    749749        }
    750750
     751        if u.srv.MaxUserNetworks >= 0 && len(u.networks) >= u.srv.MaxUserNetworks {
     752                return nil, fmt.Errorf("maximum number of networks reached")
     753        }
     754
    751755        network := newNetwork(u, record, nil)
    752756        err := u.srv.db.StoreNetwork(u.ID, &network.Network)
Note: See TracChangeset for help on using the changeset viewer.