• 沒有找到結果。

GUI allows users to facilitate the operation and invoke Blog Functions to work. These functions provide different functions according to different applications. Because this paper implements a blog system, these functions provide operations related of blog system, i.e., posting an article. In logical layer, they are established on the upper layer of those modules in section 3.1 and 3.2. Blog functions use OpenID to do identity authentication, and establish functions by using P2P and Pub/Sub System.

GUI is the pivots of the system, and connects to other parts respectively. Something likes the starting and stopping of the Web server, and how to organize the functions to applications on the P2P network, is dominated by this. But the control about web server is still

independent, it only relates to login action. In the other side, the partition about P2P has many complex and specific operations because of different applications and libraries. Thus, in order to reduce the correlation between GUI and P2P libraries and simplify the events which GUI deals with, AP Functions are the bridge of the GUI. As long as the libraries’ architecture and methods in the implementation are different even the same P2P protocol, we need to rewrite the AP Functions. In Blog System, those are usual actions, i.e., posting an article, getting articles. Therefore, in actually, Blog Functions are the key of any kind of applications in the

P2P with OpenID integration system.

4 Implementation Detail 4.1 Overview

Figure 4-1 Program Components

The diagram above depicts our program components. Users use our system via the graphical user interface (GUI). GUI communicates with other components except P2P Pub/Sub Module (FreePastry). OpenID is responsible for OpenID integration.

Static Data controls important static resources in the whole program, and is accessed by GUI and Action Functions; it also access P2P Pub/Sub Module. Action Functions are the particular capabilities about the application. P2P Pub/Sub Module only manages P2P and Pub/Sub operations.

Before we explain every partition of program in implementation, we tell about a commonly used method. The method helps us to link others in this program. It can be said that our program’s substruction. This method is Observer Pattern.

4.2 Observer Pattern

Almost the actions need to wait for being dealt with in our system. For example, querying on the P2P network, and logging with OpenID through a web site. In fact, the P2P library we adopted designs use “continuations” to avoid that a program is blocked during doing lookup. “Continuations” allow us to continue processing while receiving results. We can make other requests during waiting periods. These

behaviors create new thread, and cause that the main program can not easily obtain results in the multilayer architecture.

Observer pattern is the most commonly used design patterns. Its purpose is to define interdependence among the one-to-many objects. While an object, called subject or observable object, changes its status, the observer pattern will help the object to automatically notify other dependencies, called observer, to do some actions [24]. For instance, in our implementation, GUI is an observer and receives update information from its subjects. Action Functions is the mainly subject of GUI. GUI calls Action Functions to execute actions and waits for messages. In actually, Action Functions are intermediary layers, and observers as well. P2P Pub/Sub Module is the origin of having new threads. Action Functions receive messages from P2P Pub/Sub Module and return them to GUI. Their relations are as shown in Figure 4-2.

Figure 4-2 Observer pattern in our system

4.3 OpenID

This part includes all mechanisms about OpenID integration. The web server in our system is responsible to build a website temporarily, and the website can work and communicate with OpenID Providers. While users want to login, the windows application launches the web server via a batch file. At this moment, the web applications in the web server are usable. Our web application is a website named WebApp_OpenID, and allows users to login with OpenID. Users can input their OpenID identifiers on the website, and the website can deal with the identifier. We

assume that the port of the web server is 8080, thus, we set redirect address to http://localhost:8080/WebApp_OpenID/returnurl.jsp. Next, we find out the OpenID

Provider of user’s identifier and deliver a request to it. And the OpenID Provider exchanges messages with the website. Because our redirect address is on the localhost, it allows the user to redirect to “localhost” after logged in on the OpenID Provider website.

After completed the steps of login through OpenID Provider, users visit the redirect address. On the returnurl.jsp, we deliver result via socket stream. The stream is a string which format is: “OpenID:useridentifier”, e.g.,

“OpenID:http://user.openid.example.org”. If there are any failures or errors, the string format is: “Fail.Error Message”, i.e., “Fail.login failure”.

After above actions, the windows application uses another batch file to shutdown the web server. Actually, there are other methods to control the web server, but we adopt the batch file to control it for lower dependencies. In other words, even the version of web server changes and makes mechanisms different, we do not need to modify our program except batch files.

4.4 Static Data

Static Data is a special class which all variables and functions are static. It is similar to the existence of global variables. The common feature of these variables is that the whole program only needs the same one of each variable, such as user identifier and P2P environment parameters. Static Data includes several static

functions as well, and most of the functions are invoked in starting our system. Others are common used during program running. In addition, because all variables in this class are static, this class can keep these values only if it is called one time. We can use the class successfully cause of we called the class and initiated it before invoke

GUI.

Static Data gets the configuration file, config.properties. The configuration file decides modifiable parameters. For example, we find an empty port for binding port by using socket testing, and the beginning port is set in this file which the default value is 9701. Then we can call the function in Static Data to join a P2P network. The others in Static Data are retrieving or setting details in P2P operations and

applications.

4.5 P2P Pub/Sub Module (FreePastry)

P2P Pub/Sub Module manages all operations about P2P network and Pub/Sub system via FreePastry. It needs to be supported directly by P2P libraries, so

implementation ways almost depend on different P2P libraries.

Our system is started and joins a P2P network at initiating Static Data. The Static Data achieves the job by the functions of P2P Pub/Sub Module. It is worth noting that this partition doesn’t rely on Static Data, but static data maintains some constructions are from P2P Pub/Sub Module.

Even if it may be different according to different libraries, there are several necessary elements during the period of building a node and joining a P2P network:

1. While a node is established, it needs a port called “bindport”. The bindport is the port which deals with messages on the P2P network. The value is determined after Static Data is initiated.

2. After the node is established, it needs at least one bootstrap for joining an existent P2P network. A bootstrap is an address of another node on the P2P network. As long as a bootstrap is alive, a node can join the P2P network by it. If all bootstraps are inactive, our system will build a new P2P network by self.

Blog application is belong to data sharing, and each node has space for storing certainly. Thus, P2P Pub/Sub Module determines cache settings, the path, sizes of storage and so on and builds a node based on them. In addition, Pub/Sub system can set stuff by the established node. Moreover, FreePastry is very simple for Pub/Sub control.

Except for functions about initiating P2P environment, P2P Pub/Sub Module has others which can be used by upper layer. These functions are basic operations on the P2P network, i.e., storing data, retrieving data, etc. Components on upper layer use them to build complex functions easily.

Besides, P2P Pub/Sub Module has some data types about P2P operations. It includes the content type for node communicating and for Pub/Sub communicating on the P2P network.

4.6 Action Functions

Action Functions were born to different application’s need. The main feature of these classes is that they play not only observer but also observable roles. Because the system uses the observer pattern, the components in the upper layer can call functions in lower layer and the system still works persistently. The system can sense while receiving results, and do next steps. The reason why Action Functions are existent is to make GUI and the detail P2P operations separately. It let these components more flexible and better usable. Another advantage of Action Functions is to help GUI with dividing update contents correctly. If GUI deals with actions directly, it gets pure P2P content type or Boolean value and is difficult to recognize the meaning of these results.

Action Functions are responsible for specific abilities according to different applications. For example, a blog system should have the ability of posting an article.

At this moment, it critically controls how to store an article. We know that our system is totally distributed and the data are stored on the P2P network. Actually, these data are composed of two kinds of types, profile and article. A profile file used to save information of single personal account, such as the number of articles; an article file used to store an article, including title, content and comments.

According to the P2P protocol, every file has an only identifier. The identifier is produced by hashing a key. In other words, we can’t find the file if haven’t the key.

Thus, we define the rules how to decide a key. The key of a profile file is the user’s identifier (OpenID), and the key of an article is user’s identifier plus the serial number of the article (useridentifier#N). The serial number (N) counts from 1 and is

independent of each user. For example, a user’s identifier is

“http://user.openid.example.org”, and the key of his third article is

“http://user.openid.example.org#3”. Therefore, the program can find out all information cause of a user’s OpenID identifier.

4.7 GUI

The GUI is on the top of whole program and interacts with users. GUI implements observer pattern to be an observer. It receives information from its subjects. From the previous section, we know the interaction situations between Action Functions and GUI. In Figure 4-2, we also use observer pattern during the process of login. The main program will create another thread called ReceiveOpenID.

The thread constructs an observable class, ReceiveOpenID, and let itself be GUI’s subject. The ReceiveOpenID class opens a socket port for receiving socket streams and waits for them. Until gets the string, it notifies observers and closes the socket port and the thread finishes automatically later. Therefore, GUI obtains the result of login from the local web server, and completes the identity authentication

successfully.

In addition, the design of GUI is to be user-friendly, and presents the information to all users clearly.

4.7.1 Embedded Web Browser

This partition is non-essential part of GUI, but is important in actually. In usual situation, users visit websites by a software called web browser; popular web

browsers are Internet Explorer, Mozilla Firefox and so on. Moreover, we know that to login with OpenID needs to go on the website of OpenID provider. Users use a web browser to visit the website of OpenID Provider and a site which requests identity authentication by using OpenID. But our application is a windows application at local computer. If our system calls default web browser at users’ computer while a user log in, the user will leave the view of our main program and switch to the default web browser. After the user completed login, the web browser can’t turn the view to our application back. The serious drawback may confuse users, because it breaks off users’ emotion on operating. Users may be distracted and visit other websites on the web browser. On the other hand, users may have no pleasures to use it again because of the complexity and no intuition of the operation.

Therefore, our system contains a light and simple embedded web browser. Users can visit the login website with the embedded web browser in main program, and it will be closed after users completed login. It makes the process easy to use, intuitive and smooth. The embedded web browser is too simple to visit other websites, and can avoid distraction. Overall, although the embedded web browser is an additional component, it plays an important role which focuses user’s attention and improves user’s positive experiences.

4.7.2 Presentation Canvas

How to display the information is this part’s job. The information is nothing but articles. We can slightly typesetting and print them with simple text, but it is not convenient or intuitive. Because users may have many interactions, e.g., subscribe author’s articles, leave comments. The interface may become complex and

unnecessary while there are lots of buttons for those actions.

Therefore, our program dynamically generates html codes from the information and displays it with web page style on the Presentation Canvas. It is different to the previous embedded web browser. In addition, the program transforms the information into html codes just for the basic color and hyperlink control. The Presentation

Canvas has some hyperlinks for usual actions. If users click hyperlinks, the program can parse the hyperlinks and executes actions. The hyperlink URL formats are follows (<Link> stands for “useridentifier” or “useridentifier#N”).

URL Action (useridentifier / useridentifier#N)

http://Action.Comment.<Link> View comments / Leave a Comment

http://Action.targetlink.<Link> List all articles of the author / Link to the article http://Action.Bookmark.<Link> Bookmark it

http://Action.Subscribe.<Link> Subscribe all articles of the author

Table 4-1 Custom URL in the presentation canvas

After we transformed the information into web page style, the mode of operation is close to the user experiences, and makes users easy to get started. More importantly, it improves the presentation and scalability of operations.

4.8 Program Flow

From the above sections, we know what each component is responsible for. This section lists several complicated operation processes.

We can see the login process, as shown in Figure 4-3. The main focus is in three parts: web server, socket receiving port and embedded web browser. All of these must be close after user logging. If user’s logging is successful, the program will try to retrieve the profile file of the account and preserve a copy. If there is no profile file of the account, it will construct a new profile and keep it in the program. While it needs to update the profile file, e.g., users post an article, the program will actually store the file on the P2P network. In addition, we have to get the profile at first because it has subscription list and we need use it to initiate some settings.

The left in Figure 4-4 is subscribing mechanism. Users can use it after logging, so the program needs to check user’s logging status. At first, users choose a target, an author, and give a name for identifying. Then the program will add the target to Pub/Sub mechanism, and it can receive publishing messages instantly. Finally, it updates the subscription list from user’s profile. The right flow in Figure 4-4 is the process of posting. Users can post an article by self-account or anonymous. No matter which the signature of the article is, it still needs to update the profile of the author (self-account or anonymous) to get the article’s series number. Next, the article is stored on the P2P network. And finally, the system publishes messages to all subscribers, and all on-line subscribers will receive these messages immediately.

User login

Start web server

Open socket receiving port

Open embedded web browser Login with embedded

web browser

Receive message from web server. At the same time, close

socket receiving port.

Login Success Login Failure

Set variables in the program.

Close web server

Close embedded web browser

Waiting several seconds

To get profile himself

User login completed!

User Program

Initial subscribe stuff.

If login success If login failure

Figure 4-3 Login flow chart

Subscribe Post

Check login status Check login status

Figure 4-4 Post and subscribe flow chart

4.9 Tools and Libraries

In this program, we use numbers of open source tools and libraries for development. As shown below.

Update self-profile in the overlay

Save the article in the overlay

Publish a message to all subscribers

Post completed!

Get key and name for subscribe

Update subscribe list in the pub/sub system

Update self-profile in the overlay

Write an article

Subscribe completed!

Name Usage Version License

Java [25] Core JDK1.6 SUN

FreePastry [12] Pub/Sub P2P network 2.0_03 BSD-like

Jetty [26] Light web server 6.1.8 Apache License 2.0 OpenID4Java

[27]

OpenID-enable the Java webapp

0.9.4.339 Apache License 2.0

JDIC [28] Embedded web browser 0.9.4 LGPL

JDOM [29] Handle XML document 1.1 Apache-style open source license

Table 4-2 Tools and Libraries

5 Application Demonstration 5.1 Overview

Figure 5-1 Screenshot

This is a picture of our graphical user interface. There are several areas in the figure. Area 1 is an input box for searching; users can input an exact key of a data and find out the information. Moreover, it is the area for display the key. For example, while users link to an article through bookmarks, it shows the key of the article. And we can see that the Figure 5-1 is showing all the articles of “Anonymous”.

Area 2 has several action buttons. “Home” can link to the homepage of the user.

If the users are not logged, it redirects to the blog of Anonymous. “Post” can publish articles. “Edit Self-Profile” can edit information of self account. In addition, the user

in Figure5-1 isn’t logged, so “Edit Self-Profile” button is disabled. The detail functions and the “Login” button will be introduced in section 5.2.

Area 3 presents the information of bookmarks and subscription list. Users can choose the view by tab controller, and it is in the view of Bookmarks in Figure 5-1.

There is a bookmark, “articles from Anonymous”, in the bookmark list.

Area 4 is the Presentation Canvas (in section 4.7.2) and is responsible for how to display data. There are two hyperlinks in the top, and they are obvious instances to do actions by hyperlinks. At present, users can click these two hyperlinks, bookmark and subscribe author. Moreover, Area 5 presents messages of program, and these

messages are also logged in the system log file.

All of the functions about blog system will be introduced in section 5.3.

5.2 Login with OpenID

While clicking the “Login” button, users can see our embedded web browser as Figure5-2. It may show no pages because of less time to start the web server, and

While clicking the “Login” button, users can see our embedded web browser as Figure5-2. It may show no pages because of less time to start the web server, and

相關文件