Summary of the invention
For above-mentioned deficiency present in prior art, the present invention provides the implementation method of bi-directional synchronization between a kind of router
And system.
In order to reach foregoing invention purpose, the present invention by the following technical solutions:
The implementation method of bi-directional synchronization between a kind of router, comprises the following steps:
S1, adds plug-in unit A and plug-in unit B, plug-in unit A and plug-in unit B in the web server of router R1 and is respectively configured to provide and recognizes
Card, generation key and support webdav agreement, web server also provides for UI end configuration listening port, it is provided that preserve config literary composition
Part, it is provided that the key of certification and account and can the config1 of synchronous directory;
S2, router R2 provide UI end to set and access the URL request address that router R1 provides, it is provided that input is at router
The key that the upper registration of R1 obtains, it is provided that set catalogue config2 of router R2 end monitoring, it is provided that the time point of synchronization is arranged;
S3, router R2 provide monitored directory change and program p2 dealt with for change;
S4, router p2 program is made up of multiple threads, and between multiple threads, coordinated completes data between router
Bi-directional synchronization.
Preferably, the file configuration of described config1 is: { " port ": "<listening port of configuration>", "<key>": { "
User ": "<R2>", " syncFloder ": "<being supplied to the catalogue of R2>" }.
Preferably, the file configuration of described config2 is: " config ": { " serverURL ": " http: //
The storage catalogue that xx.xx.xx.xx:port/<R1 provides>", " key ": "<xxxxxx>", " localFloder ": "/mnt/
The monitored directory that sda/<R2 provides>", " syncTime ": "<time point of synchronization>".
Preferably, the plurality of thread includes thread A, thread B and thread C, and thread A is for the change of monitored directory, line
Journey B is for processing the event of monitoring, and whether thread C changes for the synchronous directory file of querying router R1, uses multithreading
Can be to the process comprehensive monitoring of bi-directional synchronization between router and the event of process.
Preferably, the operating procedure of described program p2 is as follows:
Step one, program initialization, and read config2 file;
Step 2, carries out corresponding environment variable settings, thus performs thread A or thread B or thread C.
Preferably, the execution process of described thread A is as follows:
S1, thread A initialize;
S2, monitored directory;
S3, stores change events chained list;
S4, it is judged that whether chained list is by lock, if chained list is by lock, then waits lock release, carries out catalogue renewal after release;
If chained list is not by lock, the most directly carry out catalogue renewal.
Preferably, the execution process of described thread B is as follows:
S1, thread B initialize;
S2, it is judged that lock in time, i.e. judges whether the time of router R1 and router R2 synchronizes, if time synchronized, then
Go to judge that whether event chained list is by lock;If time irreversibility, show thread block, until the time period is correct, then go to sentence
Whether disconnected event chained list is by lock;
S3, event chained list not by lock, then goes to judge whether thread C is synchronizing, no matter whether thread C is intended in synchronization
Traversal chained list processes event successively.
Preferably, the execution process of described thread C is as follows:
S1, thread C initialize;
S2, it is judged that judge lock in time, i.e. judges whether the time of router R1 and router R2 synchronizes, if the time is same
Step, then at interval of the synchronous directory of 5 seconds querying router R1, and whether the synchronous directory of router R1 changes in contrasting 5 seconds;If
Time irreversibility, shows thread block, until the time period is correct, then at interval of the synchronous directory of 5 seconds querying router R1 and right
In than 5 seconds, whether the synchronous directory of router R1 changes;
S3, if router R1 synchronous directory change, then judge thread B whether at local synchronization, if thread B is not in this locality
Synchronize, then the file download updated by router R1 is to local;If thread B is at local synchronization, then wait that thread B synchronously completes.
Preferably, the structure of the storage event of described thread A is as follows:
Typedef struct action Event{
Char action[20];// file activities event
Char*oldName;// ancient deed name
Char*newName;// new filename
Char*oldFolder;// old catalogue
Char*nerFolder;// new directory
}
Event change is listed as follows
{ " modify ": "<file is modified>",
" addfile ": "<newly-increased file>",
" move ": "<mobile file>",
" rename ": "<file is renamed>",
" delete ": "<file is deleted>",
" dragfile ": "<file is dragged>",
}。
Present invention also offers the system of the implementation method of bi-directional synchronization between a kind of router, it includes router R1 and road
By device R2, router R1 as active router, router R2 is as from router, and router R1 and R2 all supports to store to arrange,
Router R1 includes web server and the interface of configuration access port;Router R1 provides registering functional, provides after supporting registration
Unique certification key, it is simple to the certification of access device;Router R1 provides the support to webdav agreement;Router R1 provides
The interface of configuration synchronous directory, router R2 provides the configuration interface of local synchronization catalogue, and router R2 provides monitoring local literary composition
The program of part change;The action of router R2 offer process monitoring local file carries out the program responded;Router R2 provides and looks into
Ask the program whether synchronous directory of router R1 changes.
The present invention compared with prior art, provides the benefit that: the implementation method of bi-directional synchronization and be between router of the present invention
System achieves bi-directional synchronization between principal and subordinate's router, can realize the file-sharing between router, is different from Dropbox or computer is shared
File, computer realize share, the most at least can not power-off, router then can be understood as off line, can effectively utilize road
The resource of Internet is accessed, it is achieved between router, share file by device whole day.Additionally, this Two-way File is shared, Ke Yishi
Networking in existing little scope, forms privately owned shared circle, it may be assumed that
1, the present invention can realize real-time synchronization resource between principal and subordinate's router.
2, the present invention can realize router off line and shares resource.
3, the present invention can realize sharing resource between the local networking of little scope.
Detailed description of the invention
Below by specific embodiment, technical scheme is further described explanation.
Term is explained
WEB server is referred to as WWW (WORLD WIDE WEB) server, and major function is to provide network information and browses clothes
Business.WWW is the multimedia information inquiry instrument of Internet, is the service the most just grown up on Internet, is also to send out
Open up the fastest and current widest service.Exactly because there being WWW instrument, Internet in recent years is just made to send out rapidly
Open up, and number of users is skyrocketed through.Web server is the program that can provide document to the browser sending request.
The operation principle of Web server is the most uncomplicated, may be generally divided into following four steps: connection procedure, request process,
Answering and closedown connect.Connection procedure is exactly a kind of connection set up between Web server and its browser.
Checking whether connection procedure realizes, user can find and open this virtual file of socket, the foundation meaning of this file
It is successfully established the step for of connection procedure.Request process is exactly that the browser of Web uses this file of socket to it
Server and various request is proposed.Answering is exactly to use http protocol the request transmission come proposed in request process
To the server of Web, and then implementing task process, the result then using http protocol that task is processed is transferred to the clear of Web
Look at device, on the browser of Web, show the above-mentioned interface asked simultaneously.Closing connection is exactly when previous step-response
After process completes, the process disconnected between Web server and its browser.The aforementioned four step ring of Web server
Ring interlocks, is closely linked to, and logicality is stronger, can support multiple process, multiple thread and multiple process and multiple threads
The technology mixed mutually.
Config file, preserves configuration information to client application and uses, and ordinary circumstance, an application program is only
Have such file, before compiling, be called App.config, use Visual Studio compiling every time, all can
Copy is to the generation catalogue of application program, and Rename is: application name .config.
Thread, sometimes referred to as Lightweight Process (Lightweight Process, LWP), is the minimum of program execution stream
Unit.The thread of one standard is by Thread Id, current instruction pointer (PC), set of registers and storehouse composition.It addition, thread is
An entity in process, the ultimate unit independently dispatched by system and assign, thread oneself does not have system resource, only gathers around
There is any requisite resource that is in operation, but it can be complete with what other thread belonging to a process together shared that process had
Portion's resource.One thread can create and cancel another thread, can concurrently perform between the multiple threads in same process.
Due to the mutual restriction between thread, cause thread to be in operation and present discontinuity.Thread also have ready, block and run three
Plant basic status.Thread is a single sequential control flow process in program.Run multiple thread complete in single program simultaneously
Become different work, referred to as multithreading.
Webdav (Web-based distributed authoring and versioning) agreement is based on HTTP
One communication protocol of 1.1, its technical specification is defined by IETF RFC 2518, and it with the addition of some extensions for HTTP 1.1,
With the addition of some new methods beyond several HTTP standard method such as GET, POST, HEAD, make the application program can be directly to Web
Server direct read/write, and support rewrite file locking (lock) and unlock (unlock), it is also possible to support the version control of file
System.
The original intention of the present invention mainly realizes following demand: if there is a router in A area, have the function of storage;B
Also there is a router in area, the same storage function that provides, the renewal of the store files of existing demand B zone controller or change
Dynamic, can be uploaded in time on router A, vice versa, it is achieved the bi-directional synchronization between router.
Then needing to provide at least two routers to realize this demand, be deployed in A, B area respectively, A area is disposed
Router is provided that the request path of server, it is provided that the authority upload, downloaded, it is provided that the certification that client accesses;B area
Router provides the change function of monitoring storage device file, it is provided that upper transmitting file, the function of download file, it is provided that synchronous documents
Time period arrange.
The implementation method of bi-directional synchronization between the router of the present embodiment, comprises the following steps:
S1, adds plug-in unit A and plug-in unit B, plug-in unit A and plug-in unit B in the web server of router R1 and is respectively configured to provide and recognizes
Card, generation key and support webdav agreement, web server also provides for UI end configuration listening port, it is provided that preserve config literary composition
Part, it is provided that the key of certification and account and can the file configuration of config1, config1 of synchronous directory be: { " port ": " <
The listening port of configuration>", "<key>": { " user ": "<R2>", " syncFloder ": "<being supplied to the catalogue of R2>" } };
S2, router R2 provide UI end to set and access the URL request address that router R1 provides, it is provided that input is at router
The key that the upper registration of R1 obtains, it is provided that set catalogue config2 of router R2 end monitoring, it is provided that the time point of synchronization is arranged,
The file configuration of config2 is: { " config ": { " serverURL ": " http://xx.xx.xx.xx:port/ < R1 provides
Store catalogue>", " key ": "<xxxxxx>", " localFloder ": " monitored directory that/mnt/sda/<R2 provides>", "
SyncTime ": "<time point of synchronization>";
S3, router R2 provide monitored directory change and program p2 dealt with for change;
S4, router p2 program is made up of thread A, thread B and thread C, and between three threads, coordinated completes route
The bi-directional synchronization of data between device;
As it is shown in figure 1, the operating procedure of program p2 is as follows:
Step one, program initialization, and read config2 file;
Step 2, carries out corresponding environment variable settings, thus performs thread A or thread B or thread C;
Thread A is for the change of monitored directory, as in figure 2 it is shown, the execution process of thread A is as follows:
S1, thread A initialize;
S2, monitored directory;
S3, stores change events chained list;
S4, it is judged that whether chained list is by lock, if chained list is by lock, then waits lock release, carries out catalogue renewal after release;
If chained list is not by lock, the most directly carry out catalogue renewal.
Thread A, the structure storing event is as follows:
Typedef struct action Event{
Char action[20];// file activities event
Char*oldName;// ancient deed name
Char*newName;// new filename
Char*oldFolder;// old catalogue
Char*nerFolder;// new directory
}
Event change is listed as follows
{ " modify ": "<file is modified>",
" addfile ": "<newly-increased file>",
" move ": "<mobile file>",
" rename ": "<file is renamed>",
" delete ": "<file is deleted>",
" dragfile ": "<file is dragged>",
}。
Thread B is for processing the event of monitoring, as it is shown on figure 3, the execution process of thread B is as follows:
S1, thread B initialize;
S2, it is judged that lock in time, i.e. judges whether the time of router R1 and router R2 synchronizes, if time synchronized, then
Go to judge that whether event chained list is by lock;If time irreversibility, show thread block, until the time period is correct, then go to sentence
Whether disconnected event chained list is by lock;
S3, event chained list not by lock, then goes to judge whether thread C is synchronizing, no matter whether thread C is intended in synchronization
Traversal chained list processes event successively.
Whether thread C changes for the synchronous directory file of querying router R1, as shown in Figure 4, and the execution process of thread C
As follows:
S1, thread C initialize;
S2, it is judged that lock in time, i.e. judges whether the time of router R1 and router R2 synchronizes, if time synchronized, then
At interval of the synchronous directory of 5 seconds querying router R1, and whether the synchronous directory of router R1 changes in contrasting 5 seconds;If the time
Asynchronous, show thread block, until the time period is correct, then at interval of the synchronous directory of 5 seconds querying router R1, and contrast 5
In second, whether the synchronous directory of router R1 changes;
S3, if router R1 synchronous directory change, then judge thread B whether at local synchronization, if thread B is not in this locality
Synchronize, then the file download updated by router R1 is to local;If thread B is at local synchronization, then wait that thread B synchronously completes.
The preferred embodiment of the present invention additionally provides the system of the implementation method of bi-directional synchronization between a kind of router, and it includes road
By device R1 and router R2, router R1 as active router, router R2 is as from router, and router R1 and R2 all supports
Storing and arrange, router R1 includes web server and the interface of configuration access port;Router R1 provides registering functional, supports
Unique certification key is provided, it is simple to the certification of access device after registration;Router R1 provides the support to webdav agreement;Road
Thered is provided the interface of configuration synchronous directory by device R1, router R2 provides the configuration interface of local synchronization catalogue, and router R2 provides
The program of monitoring local file change;The action of router R2 offer process monitoring local file carries out the program responded;Route
Device R2 provides the program whether synchronous directory of querying router R1 changes.
Between router of the present invention, the realization method and system of bi-directional synchronization achieves bi-directional synchronization, energy between principal and subordinate's router
Realizing the file-sharing between router, be different from Dropbox or computer Shared Folders, computer realizes sharing, and the most at least can not break
Electricity, router then can be understood as off line, can effectively utilize router whole day to access the resource of Internet, it is achieved road
By sharing file between device.
This kind of Two-way File that the present invention uses is shared, it is possible to achieve the networking in little scope, forms privately owned shared circle.
Below in conjunction with concrete real case, the implementation method of bi-directional synchronization between the router of the present invention is described further.
The striking news router selecting model to be FWR626 is active router, and model is that NETGEAR WNDR3700 router is
From router, two-way synchronization method between the two comprises the following steps:
One, in the web server of the striking news router of FWR626, add plug-in unit A and plug-in unit B, plug-in unit A to recognize for offer Demonstrate, proving and produce password, plug-in unit B to be used for supporting webdav agreement, web server configures listening port at user interface UI end Web server provide preserve config file, it is provided that the password of certification and account and can synchronous directory config1 literary composition Part, the file configuration of config1 is:{ " port ": "<the listening port > of configuration; ", "<password>": { " user ": "<r2>", " syncFloder ": "<being supplied to the catalogue of NETGEAR WNDR3700>";
Two, the striking news router that NETGEAR WNDR3700 router provides user interface UI end to set access FWR626 carries
The URL request address of confession, it is provided that input registers, on the striking news router of FWR626d, the password obtained, it is provided that set
The catalogue config2 file of NETGEAR WNDR3700 router side monitoring, it is provided that the time point of synchronization is arranged, config2's
File configuration is: { the striking news route of " config ": { " serverURL ": " http: // 192.168.1.1:port/ < FWR626d
The storage catalogue that device provides>", " key ": "<password>", " localFloder ": "/mnt/sda/<NETGEAR
The monitored directory that WNDR3700 router provides>", " syncTime ": "<time point of synchronization>";
Three, NETGEAR WNDR3700 router provides monitored directory change and program p2 dealt with for change, p2
Program is made up of thread A, thread B and thread C, and thread A is for the change of monitored directory, and the execution process of thread A is as follows:
S1, thread A initialize;
S2, monitors configuration file catalogue;
S3, stores configuration file and updates chained list;
S4, it is judged that whether chained list is by lock, if chained list is by lock, then waits lock release, carries out catalogue renewal after release;
If chained list is not by lock, the most directly carry out catalogue renewal.
The structure of the storage event of thread A is as follows:
Typedef struct action Event{
Char action[20];//configuration files update
Char*oldName;//config.ini
Char*newName;//new config.ini
Char*oldFolder;//common
Char*nerFolder;//common
}
Event change is listed as follows:
{ " modify ": "<config.ini is revised as new config.ini>",
" rename ": "<config.ini named new config.ini>",
}。
Thread B is for processing the renewal of configuration file, and the execution process of thread B is as follows:
S1, thread B initialize;
S2, it is judged that lock in time, i.e. judge the striking news router of FWR626 and NETGEAR WNDR3700 router time
Between whether synchronize, if time synchronized, then go to judge that whether file updates chained list by lock;If time irreversibility, show thread
Block, until the time period is correct, then go to judge that whether file updates chained list by lock;
S3, file renewal chained list not by lock, then goes to judge whether thread C is synchronizing, no matter whether thread C is synchronizing
It is intended to travel through chained list and carries out the renewal of file successively.
Whether thread C changes for the synchronous directory file of the striking news router of querying router FWR626, and thread C holds
Row process is as follows:
S1, thread C initialize;
S2, it is judged that lock in time, i.e. judge the striking news router of FWR626 and NETGEAR WNDR3700 router time
Between whether synchronize, if time synchronized, then at interval of the synchronous directory of striking news router of 5 seconds inquiry FWR626, and contrast in 5 seconds
Whether the synchronous directory of the striking news router of FWR626 changes;If time irreversibility, show thread block, until the time period is just
Really, then at interval of the synchronous directory of striking news router of 5 seconds inquiry FWR626, and the striking news router of FWR626 in contrasting 5 seconds
Synchronous directory whether change;
S3, if the striking news router of FWR626 synchronous directory change, then judge thread B whether at local synchronization, if line
Journey B is not at local synchronization, then the file download updated by the striking news router of FWR626 is to local;If thread B is at local synchronization,
Then wait that thread B synchronously completes.
Above three thread is according to corresponding environment variable settings, in turn, using the striking news router of FWR626 as from
Router, and NETGEAR WNDR3700 router is as active router, completes route by coordinated between three threads
The bi-directional synchronization of configuration file more new data between device.
Above the preferred embodiments of the present invention and principle are described in detail, to those of ordinary skill in the art
Speech, the thought provided according to the present invention, detailed description of the invention will change, and these changes also should be regarded as the present invention
Protection domain.