Skip to content

Instantly share code, notes, and snippets.

@xiaokangwang
Created December 12, 2023 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaokangwang/3dc8f703879cbd3764f8ed6dfa2da047 to your computer and use it in GitHub Desktop.
Save xiaokangwang/3dc8f703879cbd3764f8ed6dfa2da047 to your computer and use it in GitHub Desktop.
SNOWFLAKE_REPO=https://gitlab.torproject.org/shelikhoo/snowflake.git
SNOWFLAKE_REPO_ANCHOR=c9e519ba0f22aac6980c442cd3bf14e81ed2cbf3
SNOWFLAKE_REPO_ANCHOROLD=a3923cd0be376051a6f91749f11bbf2b6df07f67
podman build --progress plain --target broker --tag snowflake-broker --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
podman build --progress plain --target proxy --tag snowflake-proxy --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
podman build --progress plain --target client --tag snowflake-client --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
podman build --progress plain --target server --tag snowflake-server --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
podman build --progress plain --target stund --tag snowflake-stund --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
podman build --progress plain --target httpserver --tag snowflake-httpserver --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
podman build --progress plain --target client-compare --tag snowflake-clientcompare --build-arg SNOWFLAKE_REPO=$SNOWFLAKE_REPO --build-arg SNOWFLAKE_REPO_ANCHOR=$SNOWFLAKE_REPO_ANCHOR --build-arg SNOWFLAKE_REPO_ANCHOROLD=$SNOWFLAKE_REPO_ANCHOROLD .
FROM golang:1.21-bullseye as builder
ARG SNOWFLAKE_REPO
ARG SNOWFLAKE_REPO_ANCHOR
ENV CGO_ENABLED=0
RUN git clone $SNOWFLAKE_REPO snowflake && cd snowflake && git checkout $SNOWFLAKE_REPO_ANCHOR
RUN cd snowflake/client && go get -d && go build -gcflags "all=-N -l" -o snowflake-client
RUN cd snowflake/proxy && go get -d && go build -gcflags "all=-N -l" -o snowflake-proxy
RUN cd snowflake/broker && go get -d && go build -gcflags "all=-N -l" -o snowflake-broker
RUN cd snowflake/server && go get -d && go build -gcflags "all=-N -l" -o snowflake-server
RUN go install github.com/gortc/stund@latest
FROM golang:1.21-bullseye as builderold
ARG SNOWFLAKE_REPO
ARG SNOWFLAKE_REPO_ANCHOROLD
ENV CGO_ENABLED=0
RUN git clone $SNOWFLAKE_REPO snowflake && cd snowflake && git checkout $SNOWFLAKE_REPO_ANCHOROLD
RUN cd snowflake/client && go get -d && go build -gcflags "all=-N -l" -o snowflake-client
RUN cd snowflake/proxy && go get -d && go build -gcflags "all=-N -l" -o snowflake-proxy
RUN cd snowflake/broker && go get -d && go build -gcflags "all=-N -l" -o snowflake-broker
RUN cd snowflake/server && go get -d && go build -gcflags "all=-N -l" -o snowflake-server
RUN go install github.com/gortc/stund@latest
FROM gcr.io/distroless/static as broker
COPY --from=builder /go/snowflake/broker/snowflake-broker /snowflake-broker
CMD /snowflake-broker
FROM gcr.io/distroless/static as stund
COPY --from=builder /go/bin/stund /stund
CMD /stund
FROM gcr.io/distroless/static as proxy
COPY --from=builder /go/snowflake/proxy/snowflake-proxy /snowflake-proxy
CMD /snowflake-broker
FROM debian as client
RUN apt update -y && apt upgrade -y && apt install -y curl
COPY --from=builder /go/snowflake/client/snowflake-client /snowflake-client
CMD curl
FROM debian as httpserver
RUN apt update -y && apt upgrade -y && apt install -y python3-pip
CMD python3 -m http.server
FROM gcr.io/distroless/static as server
COPY --from=builder /go/snowflake/server/snowflake-server /snowflake-server
CMD /snowflake-server
FROM debian as client-compare
RUN apt update -y && apt upgrade -y && apt install -y curl iproute2 inetutils-ping python3-pip
RUN pip install --break-system-packages exrex
COPY --from=builder /go/snowflake/client/snowflake-client /snowflake-client
COPY --from=builderold /go/snowflake/client/snowflake-client /snowflake-clientold
CMD curl
podman run --rm -it --tty --cap-add NET_ADMIN --network snowflake:interface_name=eth0 -e "TOR_PT_MANAGED_TRANSPORT_VER=1" -e "TOR_PT_CLIENT_TRANSPORTS=snowflake" -e "SNOWFLAKE_TEST_FORCELISTENADDR=127.0.0.1:1080" localhost/snowflake-client bash
/snowflake-client -ice "stun:stund:3478" -url "http://broker:8080" -fronts broker:8080 -keep-local-addresses -log "pt.log" -unsafe-logging &
curl -x socks5h://127.0.0.1:1080 http://127.0.0.1:8999
curl --output /dev/null -x socks5h://127.0.0.1:1080 http://127.0.0.1:8999/opt/httpserver/random50m
podman network create --subnet 192.5.0.0/16 snowflake
podman run -d --rm --network snowflake:interface_name=eth0,alias=broker --entrypoint "/snowflake-broker" --name "snowflake-broker" -e 'SNOWFLAKE_TEST_DEBUG=1' -v $(pwd)/data/broker:/opt/broker/ localhost/snowflake-broker -disable-tls -addr :8080 -disable-geoip -default-relay-pattern '^snowflake.torproject.net$' -allowed-relay-pattern 'snowflake.torproject.net$' -bridge-list-path '/opt/broker/bridgelist.jsonl'
podman run -d --rm --network snowflake:interface_name=eth0,alias=stund --entrypoint "/stund" --name "snowflake-stund" localhost/snowflake-stund
for i in {1..8}
do
podman run -d --rm --network snowflake:interface_name=eth0 --entrypoint "/snowflake-proxy" -e "SNOWFLAKE_TEST_ASSUMEUNRESTRICTED=1" -e "SNOWFLAKE_TEST_PROXY_DEBUG=1" localhost/snowflake-proxy -broker http://broker:8080/ -verbose -unsafe-logging -keep-local-addresses -stun "stun:stund:3478" -allowed-relay-hostname-pattern 'snowflake.torproject.net$' -allow-non-tls-relay
done
podman run -d --rm --network snowflake:interface_name=eth0,alias=httpserver --name snowflake-httpserver -v $(pwd)/data/http:/opt/httpserver/ localhost/snowflake-httpserver python3 -m http.server
podman run -d --rm --network snowflake:interface_name=eth0,alias=transientsnow1-snowflake.torproject.net --entrypoint "/snowflake-server" -e "TOR_PT_MANAGED_TRANSPORT_VER=1" -e "TOR_PT_SERVER_BINDADDR=snowflake-0.0.0.0:8888" -e "TOR_PT_SERVER_TRANSPORTS=snowflake" -e "TOR_PT_ORPORT=$(podman inspect snowflake-httpserver --format {{.NetworkSettings.Networks.snowflake.IPAddress}}):8000" localhost/snowflake-server -disable-tls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment