Skip to content

Instantly share code, notes, and snippets.

@wkgcass
wkgcass / try-windows-ovpn-tap.c
Created May 1, 2020 11:03
use windows openvpn tap
#define USERMODEDEVICEDIR "\\\\.\\Global\\"
#define SYSDEVICEDIR "\\Device\\"
#define USERDEVICEDIR "\\DosDevices\\Global\\"
#define TAP_WIN_SUFFIX ".tap"
#include <stdio.h>
#include <fcntl.h>
#include <windows.h>
#include <unistd.h>
#include <io.h>
@wkgcass
wkgcass / kcp.java
Created December 3, 2019 17:33
Fix using kcp with rsock (java impl from kcp-netty)
// base code: Copyright (c) 2017 Zheng Sun, from project kcp-netty
// added part: Copyright (c) 2019 wkgcass
public int input(ByteBuf data) {
long oldSndUna = sndUna;
long maxack = 0;
boolean flag = false;
if (log.isDebugEnabled()) {
log.debug("{} [RI] {} bytes", this, data.readableBytes());
}
@wkgcass
wkgcass / set_cpu_usage.py
Created July 31, 2019 07:45
set_cpu_usage
import sys
import random
import time
TARGET = -1
ADJUST_THRESHOLD = 100
CNT_MIN = 0
SLP_MIN = 1
SLP_MAX = 10
@wkgcass
wkgcass / result.md
Last active March 15, 2020 12:24
perf-of-nginx-vs-vertx-tls-gzip

Performance

what do I want to test

The performance of using nginx or vertx as a public network gateway.

Usually a public network gateway handles TLS and gzip, and communicate with backends with raw tcp data. So the programs are tunned to run over tls and compress http body with gzip, level 5.

result

@wkgcass
wkgcass / BaseRedisClient.java
Last active April 23, 2019 14:45
vertx redis 3.5.3 failed with redis-sentinel
package io.vertx.redis.impl;
/*
* fix that vertx redis 3.5.3 cannot connect to redis sentinel if password is present.
* what has been changed is between // --------------------START and // --------------------END
*/
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
@wkgcass
wkgcass / parse-ip.java
Last active February 16, 2019 00:28
ipv4 and ipv6 literal parser
public static String[] split(String str, String e) {
List<String> ls = new LinkedList<>();
int idx = -e.length();
int lastIdx = 0;
while (true) {
idx = str.indexOf(e, idx + e.length());
if (idx == -1) {
ls.add(str.substring(lastIdx));
break;
@wkgcass
wkgcass / RingBuffer.java
Created January 16, 2019 16:50
java: RingBuffer wrapper for nio ByteBuffer
package net.cassite.vproxy.util;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
/**
* 0 CAP
* first