Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
807d8230
Commit
807d8230
authored
8 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[fix] #739 Create a module API for specialization
parent
b176a8c7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bin/duniter
+21
-1
21 additions, 1 deletion
bin/duniter
index.js
+62
-55
62 additions, 55 deletions
index.js
with
83 additions
and
56 deletions
bin/duniter
+
21
−
1
View file @
807d8230
#!/usr/bin/env node
#!/usr/bin/env node
"
use strict
"
;
"
use strict
"
;
require
(
'
../index
'
).
statics
.
cli
();
const
co
=
require
(
'
co
'
);
const
duniter
=
require
(
'
../index
'
);
const
stack
=
duniter
.
statics
.
autoStack
();
stack
.
registerDependency
({
duniter
:
{
cli
:
[{
name
:
'
hello
'
,
desc
:
'
Says hello to the world.
'
,
requires
:
[
'
service
'
],
promiseCallback
:
(
duniterServer
)
=>
co
(
function
*
(){
console
.
log
(
'
Hello, world.
'
);
})
}]
}
});
return
co
(
function
*
(){
yield
stack
.
executeStack
();
console
.
log
(
'
Done
'
);
});
This diff is collapsed.
Click to expand it.
index.js
+
62
−
55
View file @
807d8230
"
use strict
"
;
"
use strict
"
;
const
co
=
require
(
'
co
'
);
const
co
=
require
(
'
co
'
);
const
_
=
require
(
'
underscore
'
);
const
Server
=
require
(
'
./server
'
);
const
Server
=
require
(
'
./server
'
);
const
bma
=
require
(
'
./app/lib/streams/bma
'
);
const
webmin
=
require
(
'
./app/lib/streams/webmin
'
);
const
webmin
=
require
(
'
./app/lib/streams/webmin
'
);
const
logger
=
require
(
'
./app/lib/logger
'
)(
'
duniter
'
);
const
logger
=
require
(
'
./app/lib/logger
'
)(
'
duniter
'
);
...
@@ -61,69 +61,76 @@ module.exports.statics = {
...
@@ -61,69 +61,76 @@ module.exports.statics = {
ip
:
wmHost
||
'
localhost
'
,
ip
:
wmHost
||
'
localhost
'
,
port
:
wmPort
||
9220
port
:
wmPort
||
9220
}],
httpLogs
!==
false
),
}],
httpLogs
!==
false
),
autoStack
:
()
=>
{
startNode
:
(
server
,
conf
)
=>
co
(
function
*
()
{
const
cli
=
require
(
'
./app/cli
'
);
const
stack
=
{
logger
.
info
(
"
>> NODE STARTING
"
);
// Public http interface
let
bmapi
=
yield
bma
(
server
,
null
,
conf
.
httplogs
);
// Routing documents
server
.
routing
();
// Services
registerDependency
:
(
requiredObject
)
=>
{
yield
module
.
exports
.
statics
.
startServices
(
server
);
for
(
const
command
of
(
requiredObject
.
duniter
.
cli
||
[]))
{
yield
bmapi
.
openConnections
();
cli
.
addCommand
({
name
:
command
.
name
,
desc
:
command
.
desc
},
command
.
requires
,
command
.
promiseCallback
);
}
},
logger
.
info
(
'
>> Server ready!
'
);
executeStack
:
()
=>
{
}),
startServices
:
(
server
)
=>
co
(
function
*
()
{
// Specific errors handling
process
.
on
(
'
uncaughtException
'
,
(
err
)
=>
{
// Dunno why this specific exception is not caught
if
(
err
.
code
!==
"
EADDRNOTAVAIL
"
&&
err
.
code
!==
"
EINVAL
"
)
{
logger
.
error
(
err
);
process
.
exit
(
1
);
}
});
/***************
process
.
on
(
'
unhandledRejection
'
,
(
reason
)
=>
{
* HTTP ROUTING
logger
.
error
(
'
Unhandled rejection:
'
+
reason
);
**************/
});
server
.
router
(
server
.
conf
.
routing
);
/***************
return
co
(
function
*
()
{
* UPnP
try
{
**************/
// Prepare the command
if
(
server
.
conf
.
upnp
)
{
const
command
=
cli
(
process
.
argv
);
try
{
// If ever the process gets interrupted
if
(
server
.
upnpAPI
)
{
process
.
on
(
'
SIGINT
'
,
()
=>
{
server
.
upnpAPI
.
stopRegular
();
co
(
function
*
()
{
}
yield
command
.
closeCommand
();
yield
server
.
upnp
();
process
.
exit
();
server
.
upnpAPI
.
startRegular
();
});
}
catch
(
e
)
{
});
logger
.
warn
(
e
);
// Executes the command
yield
command
.
execute
();
process
.
exit
();
}
catch
(
e
)
{
logger
.
error
(
e
);
process
.
exit
(
1
);
}
});
}
};
const
pjson
=
require
(
'
./package.json
'
);
const
duniterModules
=
[];
// Look for compliant packages
const
prodDeps
=
Object
.
keys
(
pjson
.
dependencies
);
const
devDeps
=
Object
.
keys
(
pjson
.
devDependencies
);
const
duniterDeps
=
_
.
filter
(
prodDeps
.
concat
(
devDeps
),
(
dep
)
=>
dep
.
match
(
/^duniter-/
));
for
(
const
dep
of
duniterDeps
)
{
const
required
=
require
(
dep
);
if
(
required
.
duniter
)
{
duniterModules
.
push
({
name
:
dep
,
required
});
}
}
}
}
/*******************
for
(
const
duniterModule
of
duniterModules
)
{
* BLOCK COMPUTING
console
.
log
(
'
Registering module %s...
'
,
duniterModule
.
name
);
******************/
stack
.
registerDependency
(
duniterModule
.
required
);
if
(
server
.
conf
.
participate
)
{
server
.
startBlockComputation
();
}
/***********************
* CRYPTO NETWORK LAYER
**********************/
yield
server
.
start
();
return
{};
}),
stopServices
:
(
server
)
=>
co
(
function
*
()
{
server
.
router
(
false
);
if
(
server
.
conf
.
participate
)
{
server
.
stopBlockComputation
();
}
}
yield
server
.
stop
();
return
{}
;
return
stack
;
}
)
}
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment