Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
86717f3a
Commit
86717f3a
authored
May 21, 2020
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
made the printouts of preccaned user IDs in the command line client
cleaner
parent
d0d75a98
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/root.go
+46
-15
46 additions, 15 deletions
cmd/root.go
with
46 additions
and
15 deletions
cmd/root.go
+
46
−
15
View file @
86717f3a
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/parse"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/switchboard"
"gitlab.com/elixxir/primitives/switchboard"
...
@@ -324,7 +323,7 @@ func (l *FallbackListener) Hear(item switchboard.Item, isHeardElsewhere bool, i
...
@@ -324,7 +323,7 @@ func (l *FallbackListener) Hear(item switchboard.Item, isHeardElsewhere bool, i
}
}
atomic
.
AddInt64
(
&
l
.
MessagesReceived
,
1
)
atomic
.
AddInt64
(
&
l
.
MessagesReceived
,
1
)
globals
.
Log
.
INFO
.
Printf
(
"Message of type %v from %q, %v received with fallback: %s
\n
"
,
globals
.
Log
.
INFO
.
Printf
(
"Message of type %v from %q, %v received with fallback: %s
\n
"
,
message
.
MessageType
,
*
message
.
Sender
,
senderNick
,
message
.
MessageType
,
printIDNice
(
message
.
Sender
)
,
senderNick
,
string
(
message
.
Body
))
string
(
message
.
Body
))
}
}
}
}
...
@@ -346,7 +345,7 @@ func (l *TextListener) Hear(item switchboard.Item, isHeardElsewhere bool, i ...i
...
@@ -346,7 +345,7 @@ func (l *TextListener) Hear(item switchboard.Item, isHeardElsewhere bool, i ...i
sender
,
ok
:=
user
.
Users
.
GetUser
(
message
.
Sender
)
sender
,
ok
:=
user
.
Users
.
GetUser
(
message
.
Sender
)
var
senderNick
string
var
senderNick
string
if
!
ok
{
if
!
ok
{
globals
.
Log
.
INFO
.
Printf
(
"First message from sender %v"
,
message
.
Sender
)
globals
.
Log
.
INFO
.
Printf
(
"First message from sender %v"
,
printIDNice
(
message
.
Sender
)
)
u
:=
user
.
Users
.
NewUser
(
message
.
Sender
,
base64
.
StdEncoding
.
EncodeToString
(
message
.
Sender
[
:
]))
u
:=
user
.
Users
.
NewUser
(
message
.
Sender
,
base64
.
StdEncoding
.
EncodeToString
(
message
.
Sender
[
:
]))
user
.
Users
.
UpsertUser
(
u
)
user
.
Users
.
UpsertUser
(
u
)
senderNick
=
u
.
Username
senderNick
=
u
.
Username
...
@@ -354,7 +353,7 @@ func (l *TextListener) Hear(item switchboard.Item, isHeardElsewhere bool, i ...i
...
@@ -354,7 +353,7 @@ func (l *TextListener) Hear(item switchboard.Item, isHeardElsewhere bool, i ...i
senderNick
=
sender
.
Username
senderNick
=
sender
.
Username
}
}
logMsg
:=
fmt
.
Sprintf
(
"Message from %v, %v Received: %s
\n
"
,
logMsg
:=
fmt
.
Sprintf
(
"Message from %v, %v Received: %s
\n
"
,
large
.
NewIntFromBytes
(
message
.
Sender
[
:
])
.
Text
(
10
),
printIDNice
(
message
.
Sender
),
senderNick
,
result
.
Message
)
senderNick
,
result
.
Message
)
globals
.
Log
.
INFO
.
Printf
(
"%s -- Timestamp: %s
\n
"
,
logMsg
,
globals
.
Log
.
INFO
.
Printf
(
"%s -- Timestamp: %s
\n
"
,
logMsg
,
message
.
Timestamp
.
String
())
message
.
Timestamp
.
String
())
...
@@ -494,10 +493,7 @@ var rootCmd = &cobra.Command{
...
@@ -494,10 +493,7 @@ var rootCmd = &cobra.Command{
for
i
:=
uint
(
0
);
i
<
messageCnt
;
i
++
{
for
i
:=
uint
(
0
);
i
<
messageCnt
;
i
++
{
logMsg
:=
fmt
.
Sprintf
(
logMsg
:=
fmt
.
Sprintf
(
"Sending Message to "
+
"Sending Message to "
+
"%s, %v: %s
\n
"
,
"%s, %v: %s
\n
"
,
printIDNice
(
recipientId
),
large
.
NewIntFromBytes
(
recipientId
[
:
])
.
Text
(
10
),
recipientNick
,
message
)
recipientNick
,
message
)
globals
.
Log
.
INFO
.
Printf
(
logMsg
)
globals
.
Log
.
INFO
.
Printf
(
logMsg
)
fmt
.
Printf
(
logMsg
)
fmt
.
Printf
(
logMsg
)
...
@@ -561,10 +557,9 @@ var rootCmd = &cobra.Command{
...
@@ -561,10 +557,9 @@ var rootCmd = &cobra.Command{
if
searchForUser
!=
""
{
if
searchForUser
!=
""
{
foundUser
:=
<-
udbLister
.
(
*
userSearcher
)
.
foundUserChan
foundUser
:=
<-
udbLister
.
(
*
userSearcher
)
.
foundUserChan
if
isValidUser
(
foundUser
)
{
if
isValid
,
uid
:=
isValidUser
(
foundUser
);
isValid
{
userIDBase64
:=
base64
.
StdEncoding
.
EncodeToString
(
foundUser
)
globals
.
Log
.
INFO
.
Printf
(
"Found User %s at ID: %s"
,
globals
.
Log
.
INFO
.
Printf
(
"Found User %s at ID: %s"
,
searchForUser
,
userIDBase64
)
searchForUser
,
printIDNice
(
uid
)
)
}
else
{
}
else
{
globals
.
Log
.
INFO
.
Printf
(
"Found User %s is invalid"
,
searchForUser
)
globals
.
Log
.
INFO
.
Printf
(
"Found User %s is invalid"
,
searchForUser
)
}
}
...
@@ -588,16 +583,21 @@ var rootCmd = &cobra.Command{
...
@@ -588,16 +583,21 @@ var rootCmd = &cobra.Command{
},
},
}
}
func
isValidUser
(
usr
[]
byte
)
bool
{
func
isValidUser
(
usr
[]
byte
)
(
bool
,
*
id
.
ID
)
{
if
len
(
usr
)
!=
id
.
ArrIDLen
{
if
len
(
usr
)
!=
id
.
ArrIDLen
{
return
false
return
false
,
nil
}
}
for
_
,
b
:=
range
usr
{
for
_
,
b
:=
range
usr
{
if
b
!=
0
{
if
b
!=
0
{
return
true
uid
,
err
:=
id
.
Unmarshal
(
usr
)
if
err
!=
nil
{
globals
.
Log
.
WARN
.
Printf
(
"Could not unmarshal user: %s"
,
err
)
return
false
,
nil
}
return
true
,
uid
}
}
}
}
return
false
return
false
,
nil
}
}
// init is the initialization function for Cobra which defines commands
// init is the initialization function for Cobra which defines commands
...
@@ -713,3 +713,34 @@ func init() {
...
@@ -713,3 +713,34 @@ func init() {
// initConfig reads in config file and ENV variables if set.
// initConfig reads in config file and ENV variables if set.
func
initConfig
()
{}
func
initConfig
()
{}
// returns a simple numerical id if the user is a precanned user, otherwise
// returns the normal string of the userID
func
printIDNice
(
uid
*
id
.
ID
)
string
{
for
index
,
puid
:=
range
precannedIDList
{
if
uid
.
Cmp
(
puid
)
{
return
strconv
.
Itoa
(
index
+
1
)
}
}
return
uid
.
String
()
}
// build a list of precanned ids to use for comparision for nicer user id output
var
precannedIDList
=
buildPrecannedIDList
()
func
buildPrecannedIDList
()
[]
*
id
.
ID
{
idList
:=
make
([]
*
id
.
ID
,
40
)
for
i
:=
0
;
i
<
40
;
i
++
{
uid
:=
new
(
id
.
ID
)
binary
.
BigEndian
.
PutUint64
(
uid
[
:
],
uint64
(
i
+
1
))
uid
.
SetType
(
id
.
User
)
idList
[
i
]
=
uid
}
return
idList
}
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