Skip to content

Instantly share code, notes, and snippets.

@wkgcass
wkgcass / RingBuffer.java
Created Jan 16, 2019
java: RingBuffer wrapper for nio ByteBuffer
View RingBuffer.java
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
@wkgcass
wkgcass / parse-ip.java
Last active Feb 16, 2019
ipv4 and ipv6 literal parser
View parse-ip.java
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 / BaseRedisClient.java
Last active Apr 23, 2019
vertx redis 3.5.3 failed with redis-sentinel
View BaseRedisClient.java
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;
View set_cpu_usage.py
import sys
import random
import time
TARGET = -1
ADJUST_THRESHOLD = 100
CNT_MIN = 0
SLP_MIN = 1
SLP_MAX = 10
@wkgcass
wkgcass / kcp.java
Created Dec 3, 2019
Fix using kcp with rsock (java impl from kcp-netty)
View kcp.java
// 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 / result.md
Last active Mar 15, 2020
perf-of-nginx-vs-vertx-tls-gzip
View result.md

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 / try-windows-ovpn-tap.c
Created May 1, 2020
use windows openvpn tap
View try-windows-ovpn-tap.c
#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 / test.c
Created Jan 6, 2021
lsqpack demo
View test.c
#include <stdio.h>
#include <stdlib.h>
#include "lsqpack.h"
#include "lsxpack_header.h"
void dhi_unblocked(void* hblock_ctx) {
printf("dhi_unblocked\n");
}
typedef struct st_hblock_ctx {
@wkgcass
wkgcass / TimeElemImpl.java
Last active Jan 10, 2021
TimeWheel example (TODO)
View TimeElemImpl.java
package vproxybase.util.time.timewheel;
import vproxybase.util.LogType;
import vproxybase.util.Logger;
import vproxybase.util.time.TimeElem;
public class TimeElemImpl<T> implements TimeElem<T> {
final long timeoutTs;
private final T value;
View 消息格式.md

消息格式

{
  "@type": "消息类型", // 使用@type,是因为这样可以直接利用一些json库的特性,直接反序列化到指定类型的bean
  "seq": 1, // 消息序号,long类型,从一个随机正数开始自增,通信的两端都有自己的seq
  "ack": 0, // 响应序号,0或者无该字段表示本条消息不响应任何一条消息。负数需配合type使用,-1到-65536暂作保留
  // 其余消息内容,视type而定
}