BurningBright

  • Home

  • Tags

  • Categories

  • Archives

  • Search

Spring Structure

Posted on 2017-08-10 | Edited on 2020-09-17 | In java

spring structure

  1. AliasRegistry
    定义对 Alias 的简单增删改操作
  1. SimpleAliasRegistry <—1
    实现 Alias 缓存,实现 AliasRegistry
  1. DefaultSingletonBeanRegistry <-2 <—9
    实现 SingletonBeanRegistry
  1. FactoryBeanRegistrySupport <-3
    增加了对 FactoryBean 的特殊处理 Util?
  1. AbstractBeanFactory <-4 <—12
    综合 注册器 可配置定义 的功能
  1. AbstractAutowireCapableBeanFactory <-5 <—15
    综合 Bean工厂 Bean特性定义 的功能
  1. DefaultListableBeanFactory <-6 <—8 <—10
    综合所有功能 主要实现Bean处理
  1. BeanDifinitionRegistry <-1
  1. SingletonBeanRegistry
    定义 单例 注册 获取
  1. BeanFactory
    定义 获取Bean Bean的属性
  1. HierarchicalBeanFactory <-10
    定义 父工厂 的支持
  1. ConfigurableBeanFactory <-9 <-11
    定义 配置工厂 的各种方法
  1. ListableBeanFactory <-10
    定义 条件取Bean 配置清单 的方法
  1. ConfigurableListableBeanFactory <-12 <-13 <-10
    定义 指定 忽略类型、接口 等
  1. AutowireCapableBeanFactory <-10
    定义 Bean 操作 及 回调处理

Raspberry ap mode

Posted on 2017-08-05 | Edited on 2018-12-16 | In raspberry

Install

upgrade system && update apt-get resources

1
2
3
4
5
6
7
8
9
10
/etc/apt/sources.list

deb http://mirrors.zju.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'

#deb-src http://mirrors.zju.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
#deb http://mirror.nus.edu.sg/raspbian/raspbian wheezy main contrib non-free rpi
#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

software

1
git clone https://github.com/oblique/create_ap.git

dependencies

1
sudo apt-get install util-linux procps iproute2 iw haveged hostapd dnsmasq

hostapd is the daemon thread of Host Access Point
used to provide WPA2 token check and authentication

dnsmasq used to config DNS provide DHCP service

Config

Config Git Page

Wlan config

dispatch wlan0 a static ip address

1
2
3
4
sudo vim /etc/dhcpcd.conf

interface wlan0
static ip_address=192.168.0.1/24

comments the wlan0 wpa-conf to prevent distribute host mode

1
2
3
4
5
sudo nano /etc/network/interfaces

allow-hotplug wlan0
iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

restart raspberry

1
2
3
sudo service dhcpcd restart
sudo reboot
sudo init 0


Host config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo vim /etc/hostapd/hostapd.conf

interface=wlan0
driver=nl80211
ssid=pi3ap
hw_mode=g
channel=6
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
# WPA2 mode
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

Web config

1
2
3
4
sudo nano /etc/sysctl.conf

# remove comment
net.ipv4.ip_forward=1

if not want to reboot raspberry

1
sudo sh -c "echo 1 >/proc/sys/net/ipv4/ip_forward"

For config NAT, config firewall first

1
2
3
sudo iptables -t nat -APOSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0-o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0-o eth0 -j ACCEPT

set rule autostart

1
sudo sh -c "iptables-save> /etc/iptables.ipv4.nat"

run NAT by DHCPCD need a new config

1
2
sudo nano /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat
iptables-restore </etc/iptables.ipv4.nat

restart

1
2
3
sudo service hostapdstart
sudo service dnsmasq start
sudo reboot

Tomcat-ClassLoader

Posted on 2017-08-03 | Edited on 2018-12-16 | In java

JVM class loader

JVM contain loaders:

  1. BootStrapClassLoader
    jvm need foundation class
  2. ExtClassLoader
    load $JAVA_HOME$/jre/lib/ext jars
  3. AppClassLoader
    $CLASS_PATH$ and -classpath, and class not be contained above
  4. CustomClassLoader
    self define class loader[progress]

different classloader’s class can’t use in mix,
even if the class is same package name and same class name.

JVM use delegation model

  1. pass request to father until the top
  2. if top can’t load return to sub level
  3. if the floor can’t load class throw ClassNotFoundException

java class loader

So if a same path class be put in $CLASS_PATH$ directory, java will load
$CLASS_PATH$ class first.

Tomcat class loader

Tomcat loader like this:

  1. Bootstrap
    guilde class loader $JAVA_HOME$/jre/lib/ext jars
  2. System
    tomcat container loading $CATALINA_HOME$/bin jars
  3. Common
    app common use class $CATALINA_HOME$/lib jars
  4. WebApp
    WEB-INF/classes and WEB-INF/lib developer’s workspace

Problem

When developing throw an exception from java.io.ObjectStreamClass

row:2034

1
2
3
4
5
6
7
throw new ClassCastException(
"cannot assign instance of " +
val.getClass().getName() + " to field " +
f.getDeclaringClass().getName() + "." +
f.getName() + " of type " +
f.getType().getName() + " in instance of " +
obj.getClass().getName());

From inspect the class type is a blank type only a path name.
Manually change the Class type suppress exception then jump breakpoint
the throw a exception like this:

Key Point

The Class used to communication is for other application use,
but the class contain a property that is from acceptor’s offical workspace.

Two application use a same tomcat and
put the dependent jar in $CATALINA_HOME$/lib.

It lead to a problem, the acceptor’s application load object and it’s field
class in two different classloader. one is WebAppClassLoader, on is bootstrap

  1. In object receive acceptor object use the common class jar[find in floor level]
  2. When object comes the property field’s class be found in workspace
    but object’s classloader can’t see,
    so as it’s sign target field class is just a shell.
  3. When suppress exception and jump breakpoint,
    the business class violate the loader constraint.

Cryptology in transmission

Posted on 2017-07-23 | Edited on 2020-06-17 | In theory

Password

In application password mean a text string, used to authenticate user identity.

In cryptology cipher mean a series of algorithms.
encript and decript be called cipher algorithm.

Key

A parameter in algorithm, participate calculation.
In generally bigger length of the key is, the harder to attack brutally

Symmetric-key algorithm

Usual algorithm hava DES 3DES AES.
advantage of this algorithm is performanc, disadvantage is security problem.

Once the key be attacked, the ciphertext be decripted.
So how to securely transfer symmetric key be a big problem.

Public-key cryptography

Who want to make sure security, who generate key pair.
Sender use public key to encript, receiver use private key to decript.

The advantage of this cryptograpy is security, disadvantage is performance.

Message digest

MD5 SHA hash algorithm used to create a fingerprint.
It’s an one way hash function, and unreversible.
Make sure data not dropping packet, prevent data not be replaced by attacker.

Message authentication code

First share common key first.
Sender calculate mac code by mac algorithm and key.
Receiver calculate as well, check data is not be ‘modified’.

But mac can’t resolve non-repudiation problem. Sender say the key be stolen,
the data sended by attacker.

Digital Signature

The way to resolve this problem is use public-key cryptography to calc mac.

  1. Sender use private key calc mac, send message with mac.

  2. Receiver split data, got message and mac.

  3. receiver check mac by public key, result is same with sender's mac show success.

Public-key credential

Certification Authority[CA] to manage organization’s public key.

  1. Receiver create key pair, private key manage by it’s self, public key pass to CA.
  2. CA check [offline maybe] the key is from the organization.
  3. CA sign the receiver’s public-key by itself’s private-key to generate a PKC
  4. fetch PKC
  5. Sender use CA’s public-key to check PKC,
    if successd then the public-key in PKC is the reciver’s.
  6. Encript by public-key send to receiver.
  7. Receive and decript message by private-key.

Quantum machine

Posted on 2017-07-08 | Edited on 2020-09-17 | In theory

Offical introduce

In nature world, things tend to evolve toward their lowest energy.
hot thing cool down, snow slide down hills and so on.

Image a kind of problem, which valley is the lowest?
or which space snowslide is the easiest?

Classical algorithms seek the lowest valley by send traveler to landscape
and move base on logical. This is generally most efficient to move(best track), but he is easy be traped and
can’t see the global view, only got tiny space’s solution

In contrast, quantum seek by a team, contact each other by a phenomenon called Quantum superposition.
They can feel each other, the solution is their feeling
Another phenomenon called Quantum tunneling, they can cross the hill
rather than forced to climb them.

Thinking

Quantum tunneling used this phenomenon to simulate nature[maybe god].
Quantum superposition soldiers used to simulation.
Quantum annealing is an algorithm to simulate the rule behind the problem.

More qubits to simulate, quicker to find the turth.

Maybe just like the snow on the hill, they contact with each other.
Theirself must know which space’s snow density is the lowest
and avalanche probability is the highest.

Quantum machine maybe used special condition/ simulation device/ observe device to get a problem’s solution by watch.

Hello Ant

Posted on 2017-06-29 | Edited on 2018-12-16 | In java

Create project

1
2
3
4
mkdir hello
mkdir src
cd src
vim Hello.java

Say hello to ant.

Build.xml

1
2
cd ..
vim Build.xml

Set up properties
the source file path/ class path/ jar path and so on.
the trigger target is rerun

1
2
3
4
5
<?xml version="1.0" encoding="UTF-8" ?>
<project name="hello" default="rerun" basedir=".">
<property name="src" value="src"/>
<property name="dest" value="classes"/>
<property name="jar_path" value="hello.jar"/>


Define the init method
clean workspace first
print a log and make classes directory

1
2
3
4
5
6
7
8
<target name="init" depends="clean">
<echo>+---------------------------------------------------+</echo>
<echo>| |</echo>
<echo>| B U I L D I N G ${dest} |</echo>
<echo>| |</echo>
<echo>+---------------------------------------------------+</echo>
<mkdir dir="${dest}"/>
</target>


compile project use javac command

1
2
3
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}" includeAntRuntime="false"/>
</target>


package project target to a jar and execute

1
2
3
4
5
6
<target name="build" depends="compile">
<jar jarfile="${jar_path}" basedir="${dest}"/>
</target>
<target name="run" depends="build">
<java classname="Hello" classpath="${jar_path}"/>
</target>


delete build files

1
2
3
4
5
<target name="clean">
<delete dir="${dest}" />
<delete file="${jar_path}" />
<echo>x</echo>
</target>


rerun the process

1
2
3
4
5
6
    <target name="rerun" depends="clean,run">
<ant target="run" />
<ant target="clean" />
<echo>xx</echo>
</target>
</project>

Procedure

  1. clean
  2. init
  3. compile
  4. build
  5. run
  6. 1 -> 5
  7. clean

Annotation in java

Posted on 2017-06-21 | Edited on 2018-12-16 | In java

Create Annotation

1
2
3
4
5
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DBTable {

}
  1. Target and Retention is meta annotation
  2. Target point the annotation’s place in law[SOURCE in default]
  3. Retention point the annotation avaliable time

Create More

1
2
3
4
5
6
7
8
9
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Constraints {

boolean primaryKey() default false;
boolean nullable() default true;
boolean unique() default false;

}
  1. annotation interface’s method will become ture annotation’s property
  2. interface need a default value
  3. type support Primary Type Class String Enum Annotation
1
2
3
4
5
6
7
8
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConstraintsMore {

Constraints constraints() default
@Constraints(nullable=false);

}

Annotation not support inherit
use default value implements inheritage

1
2
3
4
5
6
7
8
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SqlInteger {

int length() default 0;
Constraints constraints() default @Constraints;

}
1
2
3
4
5
6
7
8
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SqlString {

int length() default 0;
Constraints constraints() default @Constraints;

}

Thinking

Alternative way

  1. Use enumeration type to define the type in DB
    but this way lose agility.

  2. Use String to describe the type you want to define
    but ths way bind handler with DB, if DB changes
    java need to modify and recompile.

  3. Define some annotation more, to describe what you want
    this is good, but maybe a little confusion

Rtmp in raspberry

Posted on 2017-06-19 | Edited on 2018-12-16 | In raspberry

install relay

1
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

install nginx

prepare

1
2
3
4
5
6
7
8
9
sudo wget http://nginx.org/download/nginx-1.13.1.tar.gz

tar -zxvf nginx-1.13.1.tar.gz

sudo wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

unzip master.zip

cd nginx-1.13.1

compile & install

1
2
3
sudo ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
sudo make
sudo sudo make install

config

1
2
3
4
5
6
7
8
9
10
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
}
}

http://blog.csdn.net/defonds/article/details/9274479/

nginx

restart

1
2
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

1
2
3
ps -ef|grep nginx
kill -QUIT xxx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

test

1
ffmpeg -re -i "/mnt/pny/T25.mp4" -vcodec libx264 -r 15 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -b:v 500k -s 360x240 -q 10 rtmp://192.168.xxx.xxx:1935/live/demo

Char in MFC

Posted on 2017-06-16 | Edited on 2018-12-16 | In c++

character

  • char:
    prefix with str
    ANSI: strcat( ), strcpy( ), strlen( )
  • wchar_t :
    prefix with wcs
    Unicode: wcscat(), wcscpy(), wcslen()
  • WCHAR:
    typedef wchar_t WCHAR
    WCHAR == wchar_t
    macro _UNICODE in c, macro UNICODE in windows
    if no macro defined, system use ANSI compiling and run.
  • TCHAR:
    Condition define type
    If macro UNICODE defined
    typedef wchar_t TCHAR;
    If not
    typedef char TCHAR;

checkout

1
2
3
4
5
6
7
8
#ifdef   UNICODE
typedef wchar_t TCHAR;
#else
typedef unsigned char TCHAR;
#endif

typedef unsigned char CHAR;
typedef unsigned wchar_t WCHAR;

From VS2005 C++’s encoding use UNICODE in default.

translate

char -> wchar_t

1
2
3
4
5
6
7
8
9
wchar_t* Util::CharToWchar(char* c)
{
int length = strlen(c) + 1; // the text end \0 [0x00] [EOF]
wchar_t *wide = (wchar_t*)malloc(sizeof(wchar_t)*length);
memset(t, 0, length * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, c, strlen(c), wide, length);
//wcout << wide << endl;
return wide;
}

wchar_t -> char

1
2
3
4
5
6
7
8
9
10
char* Util::WcharToChar(wchar_t* wc)
{
int length = wcslen(wc) + 1;
cout << length1 << endl;
char *c = new char[length1];
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wc, -1,
c, length, NULL, NULL);
cout << c << endl;
return c;
}

Hello VC++

Posted on 2017-06-12 | Edited on 2018-12-16 | In c++

Swap Mouse Button

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

#include <tchar.h>
#include "windows.h"


using namespace std;

int main() {

// a handler
HKEY key;
// target key
LPCTSTR SubKey = _T("Control Panel\\Mouse");
if (::RegOpenKeyEx(HKEY_CURRENT_USER, SubKey, 0, KEY_ALL_ACCESS, &key) !=
ERROR_SUCCESS) {
::RegCloseKey(key);
}

char dwValue[256];
DWORD dwSize = sizeof(DWORD);
DWORD dwType = REG_SZ;
if (::RegQueryValueEx(key, _T("SwapMouseButtons"), 0, &dwType,
(LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS) {
::RegCloseKey(key);
}


if (dwValue[0] == '1') {

DWORD value = '0';
if (ERROR_SUCCESS
!= ::RegSetValueEx(key, _T("SwapMouseButtons"), 0, REG_SZ,
(CONST BYTE*) &value, 1)) {
::RegCloseKey(key);
}

SwapMouseButton(0);
} else {
DWORD value = '1';
if (ERROR_SUCCESS
!= ::RegSetValueEx(key, _T("SwapMouseButtons"), 0, REG_SZ,
(CONST BYTE*) &value, 1)) {
::RegCloseKey(key);
}

SwapMouseButton(1);
}
// release
::RegCloseKey(key);

}
  • RegOpenKeyEx/ RegQueryValueEx/ RegSetValueEx is register table function.
  • RegCloseKey when function above failed release handler.
  • SwapMouseButton used to control which button’s left right.

LPCTSTR

  • L Long no actual meaning
  • P pointer
  • C constant
  • T base on UNICODE macro, define char or wchar_t
  • STR string char*

So LPCTSTR almost const char*

If macro not define UNICODE, lead to

const char* value can’t initial LPCTSTR instance class.

Solution

1
2
#include <tchar.h>
LPCTSTR SubKey = _T("Control Panel\\Mouse");

or

1
LPCWSTR SubKey = L"Control Panel\\Mouse";

_T("ABC") the letter in _T() obtain 2 bytes same as chinese characters.

1…171819…29

Leon

282 posts
20 categories
58 tags
GitHub
Links
  • clock
  • typing-cn
  • mathjax
  • katex
  • cron
  • dos
  • keyboard
  • regex
  • sql
  • toy
© 2017 – 2024 Leon
Powered by Hexo v3.9.0
|
Theme – NexT.Muse v7.1.2