Setup CDN on DNS

Depending on how much control given to CDN provider, most to least, here are the four config options.
Assumption: we are the video content provider and our server domain name is
1. Redirect to CDN’s domain name with CNAME
2. Change my DNS so that it uses CDN’s Nameservers to resolve
3. By A record, let point to CDN’s IP.
4. Use a separate domain name for CDN access, e.g.

More details for the four options, with the same numbering.
1. we have least control, since all our DNS does is just a redirection. This is the setup of Tencent CDN, like *
2. CDN has much control. For requests of, CDN decides which IP to resolve to, e.g. depending on each user’s geographic location.
Taking CloudFlare as an example, after login at, it asks to update my DNS settng at with those nameservers:
Since multiple domain names could share one CDN’s IP, users can only access by domain name, instead of direct IP.
3. since the A record is maintained at my DNS, namely, I know the CDN’s IP my domain name is mapped to. This is not good as we loses the ability to dynamically map domain name to different IPs in different country for example.
4. this is the setup we use for our streaming server, e.g. Requests for go to our original server, and requests for go to our CDN servers.



Assuming host A B both behind NAT on the internet.
STUN: Session Traversal Utilities for NAT
A B talk to STUN server to know each other’s external IP and port state for hole punching.
The goal is to let A B directly talk to each other on UCP and sometimes TCP, if NAT is not symmetric.
This public IP is also needed in RTSP SDP when RTP over UDP.
STUN server itself communicates over UDP by default.
TURN: Traversal Using Relays around NAT
A first asks TURN server a permission, and then A sends all data to TURN, which is relayed to B.
Used for some NAT TCP, when hole punching doesn’t work.
ICE: Interactive Connectivity Establishment
Just a combination of STUN and TURN, and automatically switches between the two.

Special Years

I notice 1900 1970 and 1601 are used in time presentation.
1900: ts.tm_year is number of year since 1900.
ts is a struct, returned by localtime and gmtime, and get converted to string by asctime
1970: time_t is the number of seconds since start of this year UTC. returned by time and mktime(tm)
This is called Epoch AKA Unix timestamps and POSIX time. converted to string by ctime.
1601: FILETIME on Windows, 64bit, is the number of 0.1ms since start of this year in UTC
This year is the start of a 400-year cycle in Gregorian calendar.

Decorator Pattern

Goal: adding feature to a class, e.g. CPerson.
How: instead of subclassing, we use Person as a data member of the new class, e.g. Son.
By doing so, 1. no change to CPerson, 2. no calling the existing class’s constructor.
In this example below, we decorate CPerson so that it becomes a CSon, and 20 years later, we decorate the same person so that he becomes a CDad. CPerson’s constructor is only called once, at birth.
——————– code ——————–

class IPerson
virtual void Talk() = 0;
class CPerson
void Talk()
printf(” Person is constructed\n”);
class CSon: public IPerson
CPerson &mPerson;
CSon(CPerson &person): mPerson(person)
void Talk()
printf(” I am a son\n”);
class CDad : public IPerson
CPerson &mPerson;
CDad(CPerson &person) : mPerson(person)
void Talk()
printf(” I am a dady\n”);

int main()
const char* const msg = “person has been decorated into a”;
CPerson person;
printf(“%s son\n”, msg);
CSon son(person);
printf(“%s dady\n”, msg);
CDad dad(person);
return 0;
Person is constructed
person has been decorated into a son
I am a son
person has been decorated into a dady
I am a dady