Skip to content

How to count traffic usage of different users #2011

Description

@JuTemp
No description provided.

Activity

  1. JuTemp commented on Aug 24, 2025

    @JuTemp
    Author

    Shadowsocks-rust Config
    Here is my Shadowsocks-rust config file (desensitized)

    {
        "servers": [
            {
                "server": "0.0.0.0",
                "server_port": 23000,
                "password": "tCQVWysYldR8D4AkOf4AfGgmy1x9q2yoQJP/qYhjko8=",
                "method": "2022-blake3-chacha20-poly1305"
            },
            {
                "server": "0.0.0.0",
                "server_port": 23001,
                "password": "BoJ+dzSxqQntCCpsgRGhPHlh4JvzV+m6H4VLf+dU/Ks=",
                "method": "2022-blake3-chacha20-poly1305"
            }
        ]
    }

    It seems that Shadowsocks does not support configuring different users on the same port, and no relevant configuration was found (however, this seems to be a requirement of TCP, one port corresponds to one service)

    Shadowsocks Manager Config
    I don't know why shadowsocks sends stats periodically instead of preparing data and waiting for client requests. This is counterintuitive. I wasted a lot of time because of this.

    Here is my Shadowsocks-rust entrypoint file

    #!/bin/sh
    
    apk add jq
    
    STATS_FILE='/var/log/shadowsocks/stats'
    mkdir -p /var/log/shadowsocks
    echo user-stats-file: /var/log/shadowsocks/stats
    
    echo '{}' > ${STATS_FILE}
    
    ssserver --manager-addr 127.0.0.1:8080 &
    
    while :; do
        response=`nc -u -w 10 -l -p 8080 | head -n 1 | grep -v timeout `
        obj=`echo ${response} | cut -d ':' -f 2- `
        jq -c --argjson obj "${obj}" ". + $obj" < ${STATS_FILE} > ${STATS_FILE}.update && mv ${STATS_FILE}.update ${STATS_FILE}
    done

    When you need to request data:

    docker compose exec -it shadowsocks cat /var/log/shadowsocks/stats

    Because the method of creating a new file is used, it cannot be exposed using --volume (folders can be exposed)

    Another strange thing is that I don't know why the data returned every 10 seconds is a certain port, not all. I can't get the latest data in time by writing it this way. I can only merge the data myself.

    There is another very strange thing, I don't know why I have to restart the udp server over and over again. If I use the same udp server, I can only get the first data, like this

    nc -u -l -p 8080 | xargs -I{} echo {}
    
  2. database64128 commented on Aug 24, 2025

    @database64128
    Contributor

    It seems that Shadowsocks does not support configuring different users on the same port

    Use 2022-blake3-aes-128-gcm or 2022-blake3-aes-256-gcm instead.

    #1626 (comment) The REST API should work much better for you.

  3. zonyitoo commented on Aug 25, 2025

    @zonyitoo
    Collaborator

    Related: #1626 .

  4. JuTemp commented on Aug 26, 2025

    @JuTemp
    Author

    @database64128 Thanks for your reply.
    I also want to ask a question. My judgment is that low-performance devices (mobile phones) use chacha20, and high-performance devices (computers) use aes. Is this true?

  5. database64128 commented on Aug 26, 2025

    @database64128
    Contributor

    @JuTemp Prefer AES-based ciphers unless the CPU does not have AES instructions. Modern ARM64 processors have AES instructions, so you'll get higher throughput with lower energy use with AES-GCM compared to ChaCha20-Poly1305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions