Computer Scientist

Wednesday, 15 December 2010

Discussion on Array size, String length.

This is an revision concentrating two functions, sizeof() and strlen().

There are several manners for a programmer to define a string in C/C++ programs.

  1. char pointer: char *string; 
  2. char array: char string[100];

In order to initialize them, the following steps work.

  • define string immediately if we know what we want to define.
        char string[] = "This is what we want to defined";
        char *string = "This is what we want to defined";
  • define string first and then give the specific number afterwards.
        char string[100];
        string = "This is what we want to defined";
            CAUTION:<<This is not allowed in C++, can not assign an array to another array>>
            INSTEAD: strcpy(string, "This is what we want to defined");

        char *string;
        string = "This is what we want to defined";

In the following part, I give some different defined strings in my code. The print out is the results of two functions, sizeof() and strlen.

Here is the code:

    char *test;
    char test2[100];


    test = "This is what we want to define";
    char buffer []= "This is what we want to define";
    strcpy(test2, "This is what we want to define");
   
    std::cout << "test sizeof " << sizeof(test) << "\n";
    std::cout << "test strlen " << strlen(test) << "\n";
   
    std::cout << "buffer sizeof " << sizeof(buffer) << "\n";
    std::cout << "buffer strlen " << strlen(buffer) << "\n";
   
    std::cout << "test2 sizeof " << sizeof (test2) << "\n";
    std::cout << "test2 strlen " << strlen(test2) << "\n";

The print out is:

   test sizeof 4
   test strlen 30
   buffer sizeof 31
   buffer strlen 30
   test2 sizeof 100
   test2 strlen 30

Another aspect of the difference between strlen() and sizeof() is that strlen needs a function call to determine the string length, however, sizeof is able to give the length during the compile process. The buffer's example demonstrates this argument quite well. But, the prerequisite is that the sizeof() is able to give rather correct string length. The string should be defined and initialized as buffer example dose. In this case, bear in mind that sizeof will include the '\0' but strlent will not.

Hopefully, this makes clear of the usage of string.

Monday, 13 December 2010

Coding works of the Experiment

Here is the TODO list for experiment coding: some of them have long time to achieve and may be implemented later on due to the current works.

  * How to monitor the network bandwidth: the rough idea is to sum the number of packets during a period of time and then to calculate the amount of data per second during this period. At this point, how fine of the records should be concerned.

  * How to write a daemon to let the program running background:

  * How to stop the experiment program at anytime: Investigate how to used signal to tell the experiment process to terminate. Using IPC (Inter process call)??? The main issue is how to used Nagios to spread this instruction across all of the experiment machine.

  * How to monitor the system resources usages:

  * How to use automake to compile my own code together with the shared library of chord or sfslite. For this task, I have get some progresses on nagios snmp plugins. change the Makefile.am in ./src directory and run autoreconf --install in package directory and then automake (not sure if this is required). Then configure it and make it. PROBLEMs to be consider: 1. where is configure.ac? Is it optional for autoconf?
    ANSWER: configure.ac was called configure.in before autoconf 2.50. It can still be found in Chord and nagios snmp plugins distributions. When you modified some places in Makefile.am files or Configure.ac files, don't do anything except make it. All of the .in files will be regenerated.

Tuesday, 7 December 2010

Parsing Long Options

Find this topic in DOCUMENT of GNU C library: libc


Here I conclude some useful tips:


== return values of getopt():
  • successful
    • a character (the option name without argument)
    • a character (the option name), a pointer to char (char *optarg: argument)
  • failed
    • '?' (not included in options OR missing argument) (int optopt keeps the character)
  • -1 complete

== return values of getopt_long ():

  • successful
    • short_options
      • (same with getopt())
    • long_options
      • content of val (flag = NULL) (Tips, put corresponding short option char in val)
      • 0 (flag != NULL, put content of val into *flag)
      • (same with above two) (with argument are stored in optarg)
  • failed
    • (same with getopt())
  • -1 complete
    PS: indexptr record the index of the options in array of struct option.

Monday, 6 December 2010

Linux GUI system configuration

In order to configure linux by provided GUI, some commands are essential such as "system-cofig-firewall" will open Fedora's GUI firewall configuration window. There are also some other similar command. Using tab to investigate all of them!!!

Friday, 3 December 2010

Dive into more details of sfslite which is used by Chord official implementation

I decided to give up the usage of Openchord because it is quite difficult to use. I will back to Chord Official implementation.

Here I refresh some knowledge of sfslite and provide some useful web pages to understanding its code.








:
    One thing that is a little difficult to understand is in the Lesson 3: more than one callback are in the same procedure.
    Line 27 and 28 can be merged into "delaycb (1, 0, wrap(docallback, wrap(hello)));"
    I think I could understand it like this:
      each wrap() will produce a callback version of a function (type of callback::ref ).
      wrap(hello) provides a callback version of hello() method to function docallback( callcallback::ref ) as docallback(callback::ref)'s parameter.
      wrap(docallback, wrap(hello)) provides a callback version of docallback(callback::ref) to delaycb and asks delaycb() to register docallback(callback::ref) in event queue.

      ========Bear in mind, the return value of wrap() is callback::ref=========

      Here is the graphical expression of this mechanism:
      The usages of callback (callback::ref):
        (1). it can be passed into a callback function like docallback as its parameter and be invoked in this callback function cb();
        (2). it can be registered by a underlaying mechanism like delaycb.


Thursday, 2 December 2010

Problems suffered when I was usign SNMP

1. Set user pass-phrases problem:
    It seems to be infeasible to change pass-phrases directly in configure file. Each time, after I changed pass-phrases in configure file, I can still not make it effect even I have already restart the snmpd.
    (1). When I used snmpusm command to change password, I got a error message. This is because I was failed to assign a correct view to my current account.
    (2). When I used the same command, I got a USM generic error in rpc242. I supposed that I used wrong syntax of snmpusm command. Here is this time's typing (running locally in rpc242):
  snmpusm -v3 -l authPriv -u chenfu -a MD5 -A -x DES -X localhost passwd [ -Ca | -Cx ]

2. Running External Program:
    Actually, I can use several different "things" to run external programs using snmp on remote host.
    (1). "sh" is used to run shell script specially.
    (2). "exec" can used to run almost all of programs. <>
    ========Both "sh" and "exec" should be used by occasions when only one line result is needed. They are under a specific OID. Before, it seems to be feasible to assign aa arbitrary OID to a specific program (It is your responsibility to make sure no conflicts happen.). But now, I have never completed it. Maybe new version of SNMP forbidden this unreliable feature.========
    (3). "extend" is emerge under the situation where the manually assigning of an OID to a program is unsupported by "sh" and "exec".
    (4). "pass" is used to deal with some manually assigned OID. I am not quite familiar with "pass". As far as I know, you are able to decide what operations to do when a specific OID is looked up.

    My problem at the beginning is that I accidentally used the "exec" to run a simple script. I want to use a manually assigned OID to mark this entry. But it failed. When I turned to use "extend", it works quite well.

3. Usage of extend without assigned OID:

  1. On the remote server configure date extension in /etc/snmp/snmpd.conf. Simply add this single line at the end of the config file and reload snmpd:
    extend datecheck /bin/date
    
  2. From any client that has allowed SNMP access to the server query the datecheck with:
    ~$ snmpwalk -v2c -c public remote.server NET-SNMP-EXTEND-MIB::nsExtendOutputFull
    NET-SNMP-EXTEND-MIB::nsExtendOutputFull."datecheck" = STRING: Wed Oct 18 00:01:44 NZDT 2006
    
    That's about it. Easy way to run programs and scripts remotely, isn't it?

Tuesday, 30 November 2010

Application of Double pointer in C

1. 作为参数, 用于函数改写指针参数。




2. 用来组建多维数组。
      具体参见: http://landerchan.blogspot.com/2008/11/dynamically-allocating-multidimensional.html

Tuesday, 23 November 2010

Linkage error for Linux package installation

Troubleshooting:cannot open shared object file: No such file or directory

From MythTV

Jump to: navigation, search
This advice applies to those people running an SVN version of myth, not the tarball or packaged versions.
If you see this:
/usr/local/bin/mythbackend: error while loading shared libraries:
libmyth-0.20.so.0.20.0: cannot open shared object file: No such file or directory
after updating myth, then you probably need to do the following:
sudo locate -u
locate libmyth-0.20.so.0.20.0
That will return something like
/home/mythtv/compile/svn/mythtv/libs/libmyth/libmyth-0.20.so.0.20.0
/usr/local/lib/libmyth-0.20.so.0.20.0
The first one (for me) was the path to the folder I compiled MythTV in. The 2nd line is the installed location of libmyth. I need to add the folder its in (in this case /usr/local/lib/). You need to append that to the end of /etc/ld.so.conf. For me, I would now execute as root
echo "/usr/local/lib" >> /etc/ld.so.conf
/sbin/ldconfig
If that doesn't work try make distclean, then configure, then make and make install.
If that all fails, try a fresh checkout of the svn repository, after deleting or moving your current checkout:
svn co http://svn.mythtv.org/svn/trunk/mythtv
svn co http://svn.mythtv.org/svn/trunk/mythplugins
svn co http://svn.mythtv.org/svn/trunk/myththemes
Then go through the usual build process (configure && make && make install).

Reference: http://www.mythtv.org/wiki/Troubleshooting:cannot_open_shared_object_file:_No_such_file_or_directory

The meaning of printf(_("Some Strings"))

This is related international programming and GNU i18n. _() can be identified as the Macro of gettext() function. More details can be found here:
http://en.wikipedia.org/wiki/GNU_gettext

Monday, 8 November 2010

Install wireshark on Fedora 11

1, yum install wireshark. this is quite straight forward.

2, yum install wireshark-gnome. This this necessary!!!


As for the installation on MAC OS X, this is still on working or I would rather give up. I don't want to make my MAC bulky.

Wednesday, 18 August 2010

Shell Script

When I was using Bash Shell script to extract the available free space in the hard driver, there are several things that are worth to be noticed.

1. The importance to declare variables.

There is a segment fault when I was trying to invoke the C program from the script if the arguments that are forwarded to the C program is not declared at the beginning of the script. Next step should be to make clear what is the meaning of the parameters when the declaration was made. Those are called "variable attributes" (Burth, 73)

--------------------------------------------------------------------------------------------------
Just found that the arguments can only be declared to be read-only......

       If I did not use the declaration, there will be a segment fault. However, today I confirm that if I lost a argument of shell script such as the path of the experiment it will also lead to a segment fault!


--------------------------------------------------------------------------------------------------
I just found the main problem within this issue. The structure has problem:

df | while read content
    do
        echo ${content}
        temp=${content}
   done

echo ${content}
echo ${temp}

The situation is the same with the following snippet of code:

df | read content

echo ${content}

It can not  read anything after "df".

Tuesday, 10 August 2010

C++ Programming Tips...

Converting from a String to a integer can be achieved by a build-in function atoi() which can be found from the manual page. However the conversion from a integer to a String can not follow the similar method due to the itoa() function  is not a build-in function. It is a compiler dependent method. In C++, there is a handy method:

#include

int number;

std::ostringstream sin;
sin << number;
std::string aString= sin.str();

char* c_type_string = aString.c_str();

Friday, 16 July 2010

Agenda For the Meeting on 16th, July and Tasks to complete

I am a little behind the progress. At this time, what I should consider is what I have found from the graphs or the charts and how to defineto explain them, instead of what I know about a specific system.

There are mainly two parts of the tasks to complete:

1. (To be complete by next Wednesday or Thursday) The results and clear descriptions of the Experiment of Chord.

2. (To be complete by 11th of Aug, when Nick is coming back)

- Technical differences between Kademlia and Coral:
    Why Coral is used in small files sharing?
    Why Kademlia is used in big files sharing?

- Two methods to prove what I will find:
    Literatures of both these two methods
    Experiments on both these two methods?
      Experiments on a range of file sizes to compare the differences between these two methods.

- How to define and then to measure the closeness?

- How effectively the location of peers affect the performance of the system?


When we talking about the Experiments, there are something should be concerned:

- Closeness number of hops
- Latency - routing latency
                - file transfer latency (bandwidth, hidden conjunction problems two users who request resources are allocated into two different download networks with two different environments, one is conjuncted and one is not that busy)

- Distances (Real-distance/Political distance and topological distance) Is there relation between these distance and two previous notations? Find it out!!

- Load on each nodes (download loads, upload loads, forwarding loads and so on.)

- Routing table information stored in each node.

- Capability of each node and how to measure each node's system consumption for a system's running.

- Mobility, the distribution issue in a mesh network constructed with mobiles. Mobiles are movable and how to distribute the news to each of them is the central issue. For example, Madonna's new songs are released and how to forward these songs to each of her fans. 

Wednesday, 30 June 2010

After a long time confuse and break, I am back and ready for working enthusiastically

It is very important for now to make sure some special usages of C++ programming philosophy and its library staff.

First of all is the usage of size_t, why did not they use the int or long to represents the number instead of using size_t. I believe it is explained well in article of :


and 


very useful articles.

Thursday, 20 May 2010

Experiment with Chord

Today's works should be:

    1. How to hack the Chord code.
    2. Reading targets: 
         <1>. PC++, P87-P103 and P371-P390
         <2>. The Chinese version of Chord structure's explain.
         <3>. Two usage aspects of the Chord-like dht.
    3. Do some little initial experiments if possible.

Wednesday, 19 May 2010

How to check the open ports in Linux

Two articles on the Internet are found:

http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/security-guide/s1-server-ports.html

http://www.cyberciti.biz/faq/how-do-i-find-out-what-ports-are-listeningopen-on-my-linuxfreebsd-server/

Thursday, 13 May 2010

Hard working on Compilation

How to extract tar file in Linux with additional appendix.

tar -jxvf ***.tar.bz2

tar -zxvf ***.tar.gz

Today, I have to change my work to Fedora Linux due to the stuck on my Mac.

Firstly, I am using gmp 4.3.2 instead of 5.0.1.

Secondly, I am going to install sfslite. Let's try 0.8.17 firstly. and then 1.0.0.
    0.8.17 still does not work like the situation in my Mac.
  

Tuesday, 11 May 2010

<--Complete!!-->Concret Working Day

There are two works to do today:
    1. Complete the experimental plan at least the single machine experiments on Chord as mentioned in yesterday's meeting.
    2. Begin the experiment of Chord by construct the experimental environment. 

A little reversal according to the above descriptions is that I am beginning with the experimental environment construction. I will record the whole process for future usage:

I am constructing the environment on my Mac laptop, this means that there are some risks that some problems might emerge when I working on the Fedora Linux where is the practice environment. Just keep this in mind is fine.

                 Source files are settled in ~/src/
                 Each package has its own build directory in ~/build/

From the very beginning, I have nothing installed on my mac. I have to CMM(configure-make-make_install) everything. There is a dependency across the serials of packages which is considered to be required and necessary.

Chord ---> sfslite (SFS) ---> GMP

Chord ---> Berkeley DB

Chord visualisation ---> vis ---> GTK+ (for Mac, Maybe not necessary for Linux)

Here I list the corresponding websites of these toolkits:

Chord: http://pdos.csail.mit.edu/chord/howto.html

sfslite: http://www.okws.org/doku.php?id=sfslite

GMP: http://gmplib.org/

vis: (build-in on Mac, so not sure if GTK+is necessary The build-in vis is totally different. Need to install the vis provided by Chord separately.)


GTK+ (for Mac): http://gtk-osx.sourceforge.net/

CMM process:
1. Build GMP:
    no special, just CMM. make sure using "make check" to check the compile results after "make" it.
    In the later build, I added a "--enable-cxx" options when I configure it.

2. Build sfslite:
    need to append the "--with-sfsmisc" after "configure". "make check" is also available but nothing to check.
    The version is changed from 1.2.7 to 0.8.16 because some problems emerging when configure chord.
    There is a long story here. Choosing the right version is the most crucial step. 

3. Build Berkeley DB 4.8.26
    Not sure whether my settings are right or not. Just test it later on.
    Configure process:
            /dist/configure --enable-compat185 --enable-cxx
            when I was trying to add --enable-java there is something wrong. a file can not be founded. So I "make realclean" to wipe out every thing.
    Make process:
            When I neglected --enable-java, everything worked smoothly.
    Install process;
            It is much less than I supposed. So I successfully installed berkeley DB.

3. Build Berkeley DB 4.4.20
    It works much more smoothly than 4.8.26. One thing that I noticed is that 4.4.20 is released by sleepycat, while 4.8.26 is released by Oracle.
    I used the quite same options that I used in 4.8.26 including --enable-java. It works good this time.
Maybe 4.8.26 require a rather newer version of JDK, because the Java in Mac is not be updated for ages.
    After checking the configure.in file of Chord source, I found the accepted sfslite version is up to 4.6 from 3. <<CAUTION:>> So I changed the sfslite from version 4.4.20 to version 4.6.20 in experiments after 26/05/2013.
  
    Dramatically, the error moved to SFSlite side. the configure tool require a latest version of SFSlite!!!

大哥!!source 文件不能乱考好不好??!!再试试,全部重装。

4. Build Chord 1.0
    Quite normal process. Follow the instructions on the website where the detailed description is stated.


Something should be noticed:
    1. Choose the right version for each tool:
      GMP  5.0.1
      sfslite  0.8.17 (obtain from svn)
      Berkeley DB 4.4.20
      Chord  0.1 (lastest version)
      When retrieve the source, do use CVS, SVN or Mercurial (this kind of tools) because the tar ball of sfslite 0.8.17 in the snapshot is not complete without "svc" directory.
    2. Get ride of "cred" error when build sfslite.
      Change ./async/sysconf.h according to the latest version of the file in sfslite 1.2.7. This problem is because the latest version of Linux has no "creb" definition.

Monday, 10 May 2010

Agenda on 10/05/2010 meeting

What I next need to do is to plan an experiment to approve that
    1. the hotspots emergence and
    2. the consistent hashing's vulnerability
on load balancing.

This is for Chord. This step is used to find out the disadvantages of Chord. Because it is out of date, there must be a lot of problems.

Then evolved into Kademlia, how Kademlia solved these problems. How effectively Kademlia solved these problems? And then to prove them.

Also find some problems of Kademlia. Then to propose some methods to solve them.

Using this evolution method, to expend to BitTorrent and eDonkey.

Wednesday, 28 April 2010

Working in the midnight

A general P2P website is found today.

http://torrentfreak.com/

Monday, 26 April 2010

A rainy day with fresh air. Perfect for working. ^^

Today's work to do:
1. COMP 70100's paper, need to be complete by the end of today.
2. Refine the slides for presentation.
      i. Insert the bland sections
      ii. Refine the rest sections, experiment insertion
3. What is the problem with consistent hashing?
      i. The relationship between consistent hashing and normal hashing
      ii. The relationship between consistent hashing and Chord, Peer-to-Peer.

Thursday, 22 April 2010

Today's Work

 state-of-the-art

n.
    1. 艺术级的
adj.
    1. (科技、机电等产品)最先进的,最高级的


1. Completing the Slides of Presentation on 6th of May.
       Following each application of Peer-to-Peer approach.

2. Modifying the First Year Report for COMP70100.

Wednesday, 21 April 2010

An idea that is worth to think further

Today, when I writing my presentation slides. An idea comes into my mind, which is that how people to keep their contacts update? Because when some of their friends contacts information is not valid anymore there must be some actions to update if they desired to do so. This is quite similar with the stale routing information existing in the routing table of Peer-to-Peer system.

Futher thinking: what kind of situations can be identified to associated with the contacts out of date in social life, such as the node is failed or changed its IP address.

............

Tuesday, 16 March 2010

New Directions Found

Today, when I searched the implementation of Kadmelia, I found a Peer-to-Peer framework in GNU world, which is GNUnet. I though it is just a core Network API for programmers when they are programming network applications. However when I went through into more details of GNUnet I found that it is concerned more in Peer-to-Peer world. Here is the webpage of GNUnet:

http://gnunet.org/

In this case, the Peer-to-Peer network framework does not only exist in JAVA (JXTA) but also in open source world of GNU (GNUnet). It worth for me to check what involved into the GNUnet and JXTA.

Tuesday, 9 March 2010

Working on aMule Compilation

During most time today, I was compiling the aMule and trying to understand each option's meaning. I realized one thing, which is that I really need to learn how to use GNU make tool. A useful book is downloaded. I will go through it and get the main points regarding to my experiment from there.

Today's main progress is:

I have compiled aMule's source code (2.2.6) and installed the accomplishment successfully.

I have also found an aMule wiki page regarding "HOW TO compile aMule on Mac". I have to say that aMule community is so powerful and friendly. I suppose that there must be the manuel of compilation for aMule for all mainstream platform. Everything can be found!!!!

http://wiki.amule.org/index.php/HowTo_compile_on_Mac


Further works is:

  • learn how to use GNU make tool.
  • << Done! >> Find out if I can use IDEs like Eclipse or Visual Studio to view codes because it will make the codes more clearly to read.
  • It is time to write a story and find out some objectives instead of just doing computer geek stuff!! Try to think what should be involved. The previous papers regarding simulation would be helpful.

Monday, 8 March 2010

Compile aMule in Fedora

Before to hack into the code, the correct develop environment should be constructed. There is a fruitful instruction to achieve this is shown in the official wiki page of aMule:

http://wiki.amule.org/index.php/HowTo_Compile_In_RedHat-Fedora

Try to following this!!

Reminds of previous thinking

Some new directions appearing in my mind in last several days. Here I'd like to record them here to prevent the lost from my terribly forgetful head:

------------------------------------------------------------------------------------------------------------------------------------
A new direction is described in the article of Freedman (http://sns.cs.princeton.edu/2009/04/the-design-of-coralcdn/), which is the memory-caching system like memcached. Several web pages are found:

http://code.google.com/p/memcached/wiki/Clients

http://tangent.org/552/libmemcached.html

Furthermore, this is also remind me that I should continue the reading and investigating of Coral because I have never completed it yet. The Freedman's web page in Princeton is still a good start point to get insight into it.


---------------------------------------------------------------------------------------------------------------------------------
Another direction might be worth to follow is obfuscation, which sounds like a cheating to the firewalls to make access through them be possible. A start point is still the Wikipedia: http://en.wikipedia.org/wiki/Obfuscation


---------------------------------------------------------------------------------------------------------------------------------
As for the manipulation of eMule or aMule 's source code, it is hard to make progress because of the unfamiliarity with process of project development in Unix/Linux even in Windows or Mac, because of the Language is C instead of JAVA. Just try to study it harder.

Progress is:
I got all the source codes for both eMule (for Windows) and aMule (available for Linux like systems). I have tried to compile eMule in Visual Studio.net 2003. But the results is not that optimistic, because a compile error exists consistently.

Next step: For eMule, try using Visual Studio 2008 to compile it. For aMule, try to get the idea of the development process using C/C++.


-------------------------------------------------------------------------------------------------------------------------------------
When I was trying to compile eMule using Visual Studio 2008, some Chinese website regarding this task is searched:

http://longquanwjx.blog.163.com/blog/static/15153819201002534926266/

http://www.cnblogs.com/jzaileen/archive/2007/06/28/798369.html

http://www.verycd.com/groups/eMuleDev/209863.topic/page4

For Visual Studio.net 2003,

http://bbs.phparticle.net/thread-4271-1-4.html

http://www.wangchao.net.cn/bbsdetail_46286.html

----------------------------------------------------------------------------------------------------------------------------------
A web page of tune the aMule in Ubuntu is looks like useful later on especially in Linux environment.

http://ubuntuforums.org/showthread.php?t=526975