[CDRIVER-1326] Design POC for The MongoDB Handshake Protocol Created: 14/Jun/16  Updated: 04/Aug/16  Resolved: 16/Jun/16

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.4.0

Type: New Feature Priority: Major - P3
Reporter: Hannes Magnusson Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: intern2016
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-757 Implement The MongoDB Handshake Protocol Closed
Epic Link: mongodb-handshake

 Description   

We need to be able to set, on initial handshake, our client attributes.

Drivers that wrap mongoc need to be able to augment this dataset with information relevant for them.



 Comments   
Comment by Ian Boros [ 08/Jul/16 ]

Just an update for where I'm at. We're changing the functions to be:

bool mongoc_client_pool_set_application (pool, const char *application_name);
bool mongoc_client_set_application (client, const char *application_name);
bool mongoc_set_client_metadata (client, const char *driver_name, const char *version, const char *platform);

Each can still only be called once, but the mongoc_set_client_metadata() function sets the metadata for the whole process.

The main tasks remaining are to:
a) Dealing with the document getting too big

To deal with this we're doing the following:
1) Enforcing a maximum limit on all of the "os" and "driver" fields
2) Encoding some of the configure flags as a bitfield
3) Trimming the platform field if necessary

b) Determine what distro is running (if we're on linux)
To do this we'll have to scan the file system

Comment by Ian Boros [ 27/Jun/16 ]

Right! I enforced these limits in my code

Comment by Hannes Magnusson [ 27/Jun/16 ]

The appname and other metadata has a fixed byte length allowance. This is not the same as normal bson limits, but specific for this argument.

Comment by Ian Boros [ 17/Jun/16 ]

Thanks! Does this mean the functions will also have to take a client or client pool argument?

EDIT: nevermind. Thanks for explaining!

Comment by A. Jesse Jiryu Davis [ 17/Jun/16 ]

1) Right. Add a field bson_t metadata; to the client and pool structs. bson_init it during client and pool construction. If someone calls one of these functions, sum metadata.len (its current BSON size) and the lengths of passed-in strings. If the total is greater than 16 MB, fail. 16 MB is #defined somewhere as BSON_MAX_SIZE or something.

2) Yes, these are part of the public API that PHP and C++ drivers and C applications that use the driver directly should call.

Comment by Ian Boros [ 17/Jun/16 ]

Two questions:

1) What's it mean for the values to be too long or the app name to be too long? How big does it have to be? Is it 16mb + the max allowable bson document like it says in the link (maybe this is out of date or something totally unrelated though?):
https://jira.mongodb.org/browse/SERVER-10643

2) Are these functions meant to be called by other drivers built on top of the C Driver? If so do I still need to follow all the procedures for adding a new symbol (in CONTRIBUTING.md) for these functions?

Comment by A. Jesse Jiryu Davis [ 16/Jun/16 ]

Test with a mock_server_t that asserts the driver has passed "meta" to the server.

Comment by Hannes Magnusson [ 15/Jun/16 ]

bool mongoc_client_pool_set_application (pool, const char *application_name);
bool mongoc_client_pool_set_metadata (pool, const char *driver_name, const char *version, const char *platform);
bool mongoc_client_set_application (client, const char *application_name);
bool mongoc_client_set_metadata (client, const char *driver_name, const char *version, const char *platform);

Where these functions can only be called once.
If a value is already set, or if any of the values result in to large metadata object (or the appname too long), they fail and return false.

These functions only append to the mongoc values.

mongoc should identify itself as:

isMaster({meta: {
    application: { /* not provided unless mongoc_client[_pool]_set_application () is called */
        name: ""
    },
    driver: {
        name: "mongoc",
        version: "1.4.0"
    },
    os: {
        name: "linux",
        architecture: "x86_64",
        version: "4.4.0-22-generic"
    },
    platform: "CC=clang CFLAGS='-std=c99 -D_XOPEN_SOURCE=600' ./configure --enable-debug"
}});

The CFLAGS and CC are already available in the Makefile, and since the exact configure line is available in ./config.status --config there is a way to get the actual configure line to, somehow

When the mongoc_client_set_metadata is called the driver document will become

mongoc_client_set_metadata (client, "phongo", "1.3.0", NULL);

    driver: {
        name: "mongoc / phongo",
        version: "1.4.0 / 1.3.0"
    },
    /* ... */
    platform: "CC=clang CFLAGS='-std=c99 -D_XOPEN_SOURCE=600' ./configure --enable-debug"

Generated at Wed Feb 07 21:12:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.