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
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show 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
"
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
"
;
const
co
=
require
(
'
co
'
);
const
_
=
require
(
'
underscore
'
);
const
Server
=
require
(
'
./server
'
);
const
bma
=
require
(
'
./app/lib/streams/bma
'
);
const
webmin
=
require
(
'
./app/lib/streams/webmin
'
);
const
logger
=
require
(
'
./app/lib/logger
'
)(
'
duniter
'
);
...
...
@@ -61,69 +61,76 @@ module.exports.statics = {
ip
:
wmHost
||
'
localhost
'
,
port
:
wmPort
||
9220
}],
httpLogs
!==
false
),
autoStack
:
()
=>
{
startNode
:
(
server
,
conf
)
=>
co
(
function
*
()
{
logger
.
info
(
"
>> NODE STARTING
"
);
// Public http interface
let
bmapi
=
yield
bma
(
server
,
null
,
conf
.
httplogs
);
// Routing documents
server
.
routing
();
const
cli
=
require
(
'
./app/cli
'
);
const
stack
=
{
// Services
yield
module
.
exports
.
statics
.
startServices
(
server
);
yield
bmapi
.
openConnections
();
registerDependency
:
(
requiredObject
)
=>
{
for
(
const
command
of
(
requiredObject
.
duniter
.
cli
||
[]))
{
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
);
}
});
/***************
* HTTP ROUTING
**************/
server
.
router
(
server
.
conf
.
routing
);
process
.
on
(
'
unhandledRejection
'
,
(
reason
)
=>
{
logger
.
error
(
'
Unhandled rejection:
'
+
reason
);
});
/***************
* UPnP
**************/
if
(
server
.
conf
.
upnp
)
{
return
co
(
function
*
()
{
try
{
if
(
server
.
upnpAPI
)
{
server
.
upnpAPI
.
stopRegular
();
}
yield
server
.
upnp
();
server
.
upnpAPI
.
startRegular
();
// Prepare the command
const
command
=
cli
(
process
.
argv
);
// If ever the process gets interrupted
process
.
on
(
'
SIGINT
'
,
()
=>
{
co
(
function
*
()
{
yield
command
.
closeCommand
();
process
.
exit
();
});
});
// Executes the command
yield
command
.
execute
();
process
.
exit
();
}
catch
(
e
)
{
logger
.
warn
(
e
);
logger
.
error
(
e
);
process
.
exit
(
1
);
}
});
}
};
/*******************
* BLOCK COMPUTING
******************/
if
(
server
.
conf
.
participate
)
{
server
.
startBlockComputation
();
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
});
}
}
/***********************
* CRYPTO NETWORK LAYER
**********************/
yield
server
.
start
();
return
{};
}),
stopServices
:
(
server
)
=>
co
(
function
*
()
{
server
.
router
(
false
);
if
(
server
.
conf
.
participate
)
{
server
.
stopBlockComputation
();
for
(
const
duniterModule
of
duniterModules
)
{
console
.
log
(
'
Registering module %s...
'
,
duniterModule
.
name
);
stack
.
registerDependency
(
duniterModule
.
required
);
}
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